0

I'm doing a SOAP call and get data returned in XML. The returning XML has a markup from which I don't know how to handle. I only need all <web_get_debiteuren>.

I thought of using php SimpleXMLElement (http://www.php.net/manual/en/simplexml.examples-basic.php). But I'm not able to do something like this:

$xml = new SimpleXMLElement($result);
echo $xml->soap;

How would I be able to wals through all results <web_get_debiteuren> part of the XML file?

See XML below:

<?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>[email protected]</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>[email protected]</E-mail_werk>
            <Voornaam>Ireen</Voornaam>
            <Achternaam>Wust</Achternaam>
          </web_get_debiteuren>
        </AfasGetConnector>
      </getdatawithoptionsresult>
    </getdatawithoptionsresponse>
  </soap:body>
</soap:envelope>
2
  • If you're using soap the return should be in object/array form. How are you getting raw xml? Through one of the debug function like __getLastResponse()? Commented Feb 17, 2014 at 20:56
  • __getLastResponse() is empty. The SOAP service requires NTLM Authentication so the result is fetch by cURL. The XML that I've posted is the code that is returned from the SOAP call. Commented Feb 17, 2014 at 21:00

2 Answers 2

0

You can use xpath. Samples with possible problems:

Using xpath on a PHP SimpleXML object, SOAP + namespaces (not working..) parse an XML with SimpleXML which has multiple namespaces

But I think, you should use SoapClient if this possible..

Sign up to request clarification or add additional context in comments.

3 Comments

SoapClient doesn't return anything. The SOAP service requires NTLM Authentication so the result is fetch by cURL. The XML that I've posted is the code that is returned from the SOAP call. Having a hard time to understand the xpath, but looking at it!
I used this class, tcsoftware.net/blog/2011/08/php-soapclient-authentication, which I thinks does the same!
0

Thanks to the tip of Nostalgie of using xpath, I got it working. See code below:

$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>";
}

This will output:

Number: 10000
Number: 11000
Number: 11001
Number: 11002
Number: 11003
Number: 11004

Thanx!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.