Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php从XML文件获取数据_Php_Xml - Fatal编程技术网

php从XML文件获取数据

php从XML文件获取数据,php,xml,Php,Xml,我正在执行一个SOAP调用,并获取以XML返回的数据。返回的XML有一个我不知道如何处理的标记。我只需要所有的 我想到了使用php SimpleXMLElement()。但我不能这样做: $xml = new SimpleXMLElement($result); echo $xml->soap; 如何才能遍历XML文件的所有结果部分 请参见下面的XML: <?xml version="1.0" encoding="windows-1250"?> <soap:envelo

我正在执行一个SOAP调用,并获取以XML返回的数据。返回的XML有一个我不知道如何处理的标记。我只需要所有的

我想到了使用php SimpleXMLElement()。但我不能这样做:

$xml = new SimpleXMLElement($result);
echo $xml->soap;
如何才能遍历XML文件的所有结果
部分

请参见下面的XML:

<?xml version="1.0" encoding="windows-1250"?>
<soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:body>
    <getdatawithoptionsresponse xmlns="urn:Afas.Profit.Services">
      <getdatawithoptionsresult>
        <AfasGetConnector>
          <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xs:element name="AfasGetConnector">
              <xs:complexType>
                <xs:choice maxOccurs="unbounded">
                  <xs:element name="web_get_debiteuren">
                    <xs:complexType>
                      <xs:sequence>
                        <xs:element name="Nummer_debiteur" type="xs:string" minOccurs="0"/>
                        <xs:element name="Naam_debiteur" type="xs:string" minOccurs="0"/>
                        <xs:element name="E-mail_werk" type="xs:string" minOccurs="0"/>
                        <xs:element name="Voornaam" type="xs:string" minOccurs="0"/>
                        <xs:element name="Achternaam" type="xs:string" minOccurs="0"/>
                      </xs:sequence>
                    </xs:complexType>
                  </xs:element>
                </xs:choice>
              </xs:complexType>
            </xs:element>
          </xs:schema>
          <web_get_debiteuren>
            <Nummer_debiteur>10000</Nummer_debiteur>
            <Naam_debiteur>Test</Naam_debiteur>
            <Voornaam>Hans</Voornaam>
            <Achternaam>Klok</Achternaam>
          </web_get_debiteuren>
          <web_get_debiteuren>
            <Nummer_debiteur>11000</Nummer_debiteur>
            <Naam_debiteur>Sven</Naam_debiteur>
            <E-mail_werk>e@mail.com</E-mail_werk>
            <Voornaam>Sven</Voornaam>
            <Achternaam>Kramer</Achternaam>
          </web_get_debiteuren>
          <web_get_debiteuren>
            <Nummer_debiteur>11001</Nummer_debiteur>
            <Naam_debiteur>Ireen</Naam_debiteur>
            <E-mail_werk>i@reen.nl</E-mail_werk>
            <Voornaam>Ireen</Voornaam>
            <Achternaam>Wust</Achternaam>
          </web_get_debiteuren>
        </AfasGetConnector>
      </getdatawithoptionsresult>
    </getdatawithoptionsresponse>
  </soap:body>
</soap:envelope>

10000
测验
汉斯
克鲁克
11000
斯文
e@mail.com
斯文
克莱默
11001
伊岚
i@reen.nl
伊岚
武斯特
您可以使用。可能存在问题的样本:


但是我认为,如果可能的话,您应该使用SoapClient。

多亏了使用xpath的怀旧技巧,我让它工作起来了。见下面的代码:

$response = simplexml_load_string( $result ,NULL, NULL, "http://schemas.xmlsoap.org/soap/envelope/" );

$response->registerXPathNamespace("site", "urn:Afas.Profit.Services");
$_res = $response->xpath('//site:AfasGetConnector');
#$_res = $_res->AfasGetConnector;

foreach($_res[0]->web_get_debiteuren AS $deb){
  echo "Number: ".$deb->Nummer_debiteur."<br>";
}

塔克斯

如果您使用的是soap,那么返回应该是对象/数组形式。如何获取原始xml?通过调试函数之一,如uu getLastResponse()?u getLastResponse()为空。SOAP服务需要NTLM身份验证,因此结果是通过cURL获取。我发布的XML是从SOAP调用返回的代码。SoapClient不返回任何内容。SOAP服务需要NTLM身份验证,因此结果是通过cURL获取。我发布的XML是SOAP调用返回的代码。很难理解xpath,但是看看它!你可以试试这个解决方案——我用过这个类,我想也是这样!
Number: 10000
Number: 11000
Number: 11001
Number: 11002
Number: 11003
Number: 11004