-2

I am trying to get all the elements and values as array from the below soap response. But I am only getting elements but no values.

I have used this parser to get the elements and values. Thanks in advance.

Here is the code I am using,

 $response = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header/> <soapenv:Body> <toy:SearchReq xmlns:toy="www.something.com/toy" xmlns:gen="www.something.com/gen"> <gen: manufacturedIn="SomePlace"/> <toy:SearchToy> <toy:SearchType> <gen:Shop Code="WALMART"/> </toy:SearchType> </toy:SearchToy> <toy:SearchToy> <toy:SearchType> <gen:Shop Code="AMAZON"/> </toy:SearchType> </toy:SearchToy> </toy:SearchReq> </soapenv:Body> </soapenv:Envelope>'; $doc = simplexml_load_string($response); $path = array($doc ->children('http://schemas.xmlsoap.org/soap/envelope/') ->Body ->children('www.something.com/toy')); foreach($path as $elem){ print_r($elem); $elemChild = $elem->children('www.something.com/gen'); var_dump($elemChild); } 

2 Answers 2

0

You can read SOAP messages by registering the namespace - you only need the namespace bit if you care about the SOAP parts of the message.

$xml = simplexml_load_string($xml); $xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/'); foreach ($xml->xpath('//toy') as $toy) { print_r($toy); } 
Sign up to request clarification or add additional context in comments.

1 Comment

The resolution is not working. I have tried that already. Also, I need all the child nodes in a single search.May be for an unknown response elements with known namespaces.Thanks in advance.
0

See complete reference here: https://stackoverflow.com/a/38783380/6511851

$sxe = new SimpleXMLElement($response); //in $response variable it's an XML file or response $sxe->registerXPathNamespace('d', 'urn:schemas-microsoft-com:xml-diffgram-v1'); $result = $sxe->xpath("//NewDataSet"); echo "<pre>"; foreach ($result[0] as $title) { print_r($title); } 

For more information visit site: https://vaja906programmingworld.wordpress.com/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.