1

I have been spending hours trying to parse a SOAP response that I have no control over. I have tried numerous methods I found on SO with no luck.

Here is the response body I get from edge browser:

<?xml version='1.0' encoding='UTF-8'?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <SOAP-ENV:Body> <ns1:gXMLQueryResponse xmlns:ns1="urn:com-photomask-feconnect-IFeConnect" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <return xsi:type="xsd:string">&lt;?xml version = &apos;1.0&apos; encoding = &apos;UTF-8&apos;?&gt; &lt;ROWSET&gt; &lt;ROW num=&quot;1&quot;&gt; &lt;CUSTOMER_NAME&gt;HITACHI&lt;/CUSTOMER_NAME&gt; &lt;/ROW&gt; &lt;/ROWSET&gt; </return> </ns1:gXMLQueryResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope> 

I'm trying to get the CUSTOMER_NAME value.

Here is the code I am using:

 $client = new SoapClient($urla, array('trace' => 1)); try { $result = $client->__soapCall("gXMLQuery", $params); $response = ($client->__getLastResponse()); $xml = simplexml_load_string($response); $rows = $xml->children('SOAP-ENV', true)->Body->children('ns1', true)->gXMLQueryResponse->return->ROWSET->ROW; foreach ($rows as $row) { $customer = $row->CUSTOMER_NAME; echo $customer; } } catch (SoapFault $e) { } 
1
  • When I echo the response, this is what I get: <?xml version = '1.0' encoding = 'UTF-8'?> <ROWSET> <ROW num="1"> <CUSTOMER_NAME>HITATCHI</CUSTOMER_NAME> </ROW> </ROWSET> " Commented Jan 3, 2020 at 21:09

1 Answer 1

1

return is a string, you need to parse it first before you can access it using SimpleXML.

First you need to decode the string using html_entity_decode, after that you can load the decoded string with simplexml_load_string:

$return = $xml->children('SOAP-ENV', true)->Body->children('ns1', true)->gXMLQueryResponse->return; $decodedReturn = html_entity_decode($return, ENT_QUOTES | ENT_XML1, 'UTF-8'); $rowset = simplexml_load_string($decodedReturn); echo $rowset->ROW->CUSTOMER_NAME; 
Sign up to request clarification or add additional context in comments.

4 Comments

fromvega, how would I do that?
how did you get a value into the $return value, or should that be the SOAP response?
I get an error: Notice: Trying to get property of non-object in D:\xampp\htdocs\appa\soap.php on line 84. it's this code: echo $rowset->ROW->CUSTOMER_NAME;
Make sure that $decodedReturn holds a valid XML string and then use it as a reference to access the data with simplexml.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.