Skip to content
Advertisement

PHP WSDL response as object

I am sending a request for response to a WSDL in PHP (code below). The response is structured in a way that I’m not sure how to extract data from it. It comes back as an object with the XML inside. Is there a standard way of parsing the XML of this object?

Here is my code:

JavaScript

?>

Here is the response I get. How do I pull the XML out and parse for keys?

JavaScript

Here is the WSDL response I get when I use SoapUI:

JavaScript

Advertisement

Answer

It looks like your $soapCall->LoadCustomerDocumentsResult->any contains valid XML, so you can just use any of built-in XML classes:

JavaScript

or

JavaScript

Or you can try helper classes from composer – something like phpro/soap-client

Updated: Ok, so you have a bit more complicated xml than usual, so here are some tips:

  1. to make your xml valid you need only one outer element, so
JavaScript

will fix it.

  1. You have unusual namespace in your second element. To make it work, you need to use registerXPathNamespace function:
JavaScript

Next you need to get your element by namespace:

JavaScript

Actually after $diffgram[0] you can use your second element as regular xml.

Hope it helps.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement