-1

我实际上在 PHP 中使用 XML 文件。我将 simpleXML 用于我的基本 xml 文件。但现在我有一个不同的 xml 文件,而 SimpleXML 还不够好。从我的 xml 我需要从 zbozi kodpočet 获取。你有什么解决办法吗?

<?xml version="1.0" encoding="utf-8"?>
<DataSet xmlns="http://www.atcomp.cz/webservices">
  <xs:schema id="StavySkladu" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xs:element name="StavySkladu" msdata:IsDataSet="true" msdata:Locale="cs-CZ">
      <xs:complexType>
        <xs:choice maxOccurs="unbounded">
          <xs:element name="Zbozi">
            <xs:complexType>
              <xs:attribute name="kod" type="xs:string" />
              <xs:attribute name="pocet" type="xs:int" />
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:complexType>
    </xs:element>
  </xs:schema>
  <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
    <StavySkladu xmlns="">
      <Zbozi diffgr:id="Zbozi1" msdata:rowOrder="0" kod="C5709A" pocet="0"/>
      <Zbozi diffgr:id="Zbozi2" msdata:rowOrder="1" kod="C5708A" pocet="0"/>
      <Zbozi diffgr:id="Zbozi3" msdata:rowOrder="2" kod="C5718A" pocet="45"/>
      <Zbozi diffgr:id="Zbozi4" msdata:rowOrder="3" kod="EC13S050088" pocet="2"/>
      <Zbozi diffgr:id="Zbozi5" msdata:rowOrder="4" kod="EC376123GB" pocet="3"/>
      <Zbozi diffgr:id="Zbozi6" msdata:rowOrder="5" kod="EC800302" pocet="0"/>
      <Zbozi diffgr:id="Zbozi7" msdata:rowOrder="6" kod="EC806392" pocet="2"/>
      <Zbozi diffgr:id="Zbozi8" msdata:rowOrder="7" kod="EC800202" pocet="1"/>
      <Zbozi diffgr:id="Zbozi9" msdata:rowOrder="8" kod="EC806872" pocet="1"/>
      <Zbozi diffgr:id="Zbozi10" msdata:rowOrder="9" kod="EPC163071" pocet="16"/>
      <Zbozi diffgr:id="Zbozi11" msdata:rowOrder="10" kod="EMD157021" pocet="0"/>
      <Zbozi diffgr:id="Zbozi12" msdata:rowOrder="11" kod="EPC834031" pocet="0"/>
      <Zbozi diffgr:id="Zbozi13" msdata:rowOrder="12" kod="EPC825341" pocet="17"/>
    </StavySkladu>
  </diffgr:diffgram>
</DataSet>
4

1 回答 1

2
<?php
$xml = new SimpleXMLElement($xmlstr);
$xml->registerXPathNamespace('xs', 'http://www.w3.org/2001/XMLSchema');
$path =' xs:schema/xs:element/xs:complexType/xs:choice/xs:element/xs:complexType/xs:attribute';

foreach($xml->xpath($path) as $child)
{
    $attributes = $child->attributes();
    echo "{$attributes['name']}\n";
}
?>
于 2013-02-17T15:10:43.210 回答