Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble Parsing SOAP response in PHP using simplexml
    primarykey
    data
    text
    <p>I'm using cURL to POST a SOAP request. The response is as follows:</p> <pre><code>&lt;env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"&gt; &lt;env:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"&gt; &lt;wsa:To&gt;http://www.w3.org/2005/08/addressing/anonymous&lt;/wsa:To&gt; &lt;wsa:Action&gt;http://www.csapi.org/schema/parlayx/common/v3_1/TerminalLocationPort/getLocationForGroupResponse&lt;/wsa:Action&gt; &lt;/env:Header&gt; &lt;env:Body&gt; &lt;ns2:getLocationForGroupResponse xmlns:ns2="http://www.csapi.org/schema/parlayx/terminal_location/v3_1/local"&gt; &lt;ns2:result&gt; &lt;address&gt;234983&lt;/address&gt; &lt;reportStatus&gt;Retrieved&lt;/reportStatus&gt; &lt;currentLocation&gt; &lt;latitude&gt;12.5665&lt;/latitude&gt; &lt;longitude&gt;43.7708&lt;/longitude&gt; &lt;timestamp&gt;2012-01-03T17:06:16.805+01:30&lt;/timestamp&gt; &lt;/currentLocation&gt; &lt;/ns2:result&gt; &lt;ns2:result&gt; &lt;address&gt;423903&lt;/address&gt; &lt;reportStatus&gt;Retrieved&lt;/reportStatus&gt; &lt;currentLocation&gt; &lt;latitude&gt;12.2165&lt;/latitude&gt; &lt;longitude&gt;43.6518&lt;/longitude&gt; &lt;timestamp&gt;2012-01-03T17:06:16.824+01:30&lt;/timestamp&gt; &lt;/currentLocation&gt; &lt;/ns2:result&gt; &lt;/ns2:getLocationForGroupResponse&gt; &lt;/env:Body&gt; &lt;/env:Envelope&gt; </code></pre> <p>I use this to decode:</p> <pre><code>$err = curl_error($soap_do); $result = curl_exec($soap_do); $xml = simplexml_load_string($result); $ns = $xml-&gt;getNamespaces(true); $soap = $xml-&gt;children($ns['env']); $getaddressresponse = $soap-&gt;body-&gt;children($ns['ns2']); foreach ($getaddressresponse-&gt;children() as $item) { echo (string) $item-&gt;address . '&lt;br /&gt;'; } </code></pre> <p>I'm having trouble decoding this with SimpleXML. This <a href="https://stackoverflow.com/questions/3928350/how-to-parse-soap-response">link</a> seems most relevant to my situation but I'm unable to apply it to my case as the simpleXML element just</p> <pre><code>Warning: SimpleXMLElement::children() [simplexmlelement.children]: Node no longer exists in C:\.php on line 33 /*(line with the for each statement)*/ </code></pre> <p>Any suggestions?</p> <p><strong>UPDATE:</strong> If the server responds with the following error, how would I detect it..?</p> <pre><code>&lt;env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"&gt; &lt;env:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"&gt; &lt;wsa:To&gt;http://www.w3.org/2005/08/addressing/anonymous&lt;/wsa:To&gt; &lt;wsa:Action&gt;http://www.w3.org/2005/08/addressing/fault&lt;/wsa:Action&gt; &lt;/env:Header&gt; &lt;env:Body&gt; &lt;env:Fault&gt; &lt;faultcode&gt;env:Server&lt;/faultcode&gt; &lt;faultstring&gt;Service Exception&lt;/faultstring&gt; &lt;detail&gt; &lt;ns1:ServiceException xmlns:ns1="http://www.csapi.org/schema/parlayx/common/v3_1" xmlns:ns2="http://www.csapi.org/schema/parlayx/terminal_location/v3_1/local"&gt; &lt;messageId&gt;SVC004&lt;/messageId&gt; &lt;text&gt;Trip not Found for this MSISDN&lt;/text&gt; &lt;/ns1:ServiceException&gt; &lt;/detail&gt; &lt;/env:Fault&gt; &lt;/env:Body&gt; &lt;/env:Envelope&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload