1

I'm afraid I'm at a loss on how to parse this XML with namespaces and prefixes. Here's the SOAP reply I get from a Curl request:

<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>
    <getproductpricekonfigurationresponse xmlns="https://service.printapi.de/interface/">
      <getproductpricekonfigurationresult>
        <xs:schema id="ProduktPreisKonfiguration" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"></xs:schema>
        <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
          <produktpreiskonfiguration xmlns>
            <produktkonfiguration diffgr:id="ProduktKonfiguration1" msdata:roworder="0" diffgr:haschanges="inserted">
              <idobjekt>4</idobjekt>
              <idformat>30</idformat>
              <ustidentnr>
                <objektpreisnetto>18.77</objektpreisnetto>
                <mwstwert>6.01</mwstwert>
              </ustidentnr>
            </produktkonfiguration>
          </produktpreiskonfiguration>
        </diffgr:diffgram>
      </getproductpricekonfigurationresult>
    </getproductpricekonfigurationresponse>
  </soap:body>
</soap:envelope>

If I wanted to echo for example the "objektpreisnetto" node, how would I do it?

Edit: here's some things I've tried (amongst others):

$xml = simplexml_load_string($soap);

$result = $xml->children('http://schemas.xmlsoap.org/soap/envelope/')
    ->children('https://service.printapi.de/interface/')
    ->getproductpricekonfigurationresult
    ->objektpreisnetto;

echo $result->objektpreisnetto;

That returns nothing, but I'm sure I'm not handling the children part correctly.

Here's an even more basic example I tried, which also returns nothing:

$xml = simplexml_load_string($soap);
foreach ($xml->children('http://schemas.xmlsoap.org/soap/envelope/') as $child)
{
  echo "Child node: " . $child . "<br>";
}

Should that not at least return one child node? Any insight would be greatly appreciated!

Marc
  • 229
  • 3
  • 14
  • Why not use a SOAP client instead of simpleXML? Can you show what you have tried and be specific about what is not working? – Mike Brant Mar 31 '14 at 15:40
  • the XML is not valid: http://www.xmlvalidation.com – michi Mar 31 '14 at 16:28
  • I'm not using SOAP client because the SOAP service I connect to is using HTTP authorization, so I use curl for that. – Marc Apr 01 '14 at 08:03

2 Answers2

1

SoapClient handles HTTP authentication by setting login and password within the SoapClient options, did you try ?

Then use a Wsdl to php generator to help you get the corresponding PHP classes that you'll use as classmap, try https://www.wsdltophp.com.

So you'll only deal with PHP objects and you won't have to parse anything.

Mikaël DELSOL
  • 760
  • 5
  • 15
  • It is my understanding that SoapClient does not handle the type of HTTP auth that is used by the remote server. (The request itself is protected by username/password, not the wsdl file.) However I tried it anyway, and it did not work. I found some suggestions to get around this, which is using curl to login and download a local copy of the wsdl file, and have SoapClient handle the local file instead of the password-protected remote file. I'm trying that workaround now, and will have a go at your wsdltophp script. – Marc Apr 01 '14 at 13:21
1

I managed to get this working!

First I use curl to login and send the SOAP request as outlined in this answer: https://stackoverflow.com/a/7157785/1121877

Then I load the returned XML with simplexml_load_string as outlined over here: https://stackoverflow.com/a/8275835/1121877

So thanks to everybody for sharing their knowledge!

Community
  • 1
  • 1
Marc
  • 229
  • 3
  • 14