Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing/Interpreting XML retrieved from a web service in PHP
    primarykey
    data
    text
    <p>I am sending a HTTP GET request to the web service of an external company. This is coming back fine, but I am running into problems with the interpretation of what comes back. The response is sent in XML. I have tried to use SimpleXML (which I admit, I am not familiar with) and cannot figure it out. What I need to do is assign something received in the XML to a PHP variable and then echo it. The variable I need to assign is "SessionToken" to $sessionid. How do I do this?</p> <p>Here is an example of my code:</p> <pre><code> error_reporting(E_ALL); $request = 'http://ws.examplesite.com/test/test.asmx/TestFunction?Packet=&lt;Packet&gt;&lt;Email&gt;test@example.com&lt;/Email&gt;&lt;Password&gt;testpassword&lt;/Password&gt;&lt;/Packet&gt;'; $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, true); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); curl_close($session); $status_code = array(); preg_match('/\d\d\d/', $response, $status_code); switch( $status_code[0] ) { case 200: break; case 503: die('Your call to Web Services failed and returned an HTTP status of 503. That means: Service unavailable. An internal problem prevented us from returning data to you.'); break; case 403: die('Your call to Web Services failed and returned an HTTP status of 403. That means: Forbidden. You do not have permission to access this resource, or are over your rate limit.'); break; case 400: die('Your call to Web Services failed and returned an HTTP status of 400. That means: Bad request. The parameters passed to the service did not match as expected. The exact error is returned in the XML response.'); break; default: die('Your call to Web Services returned an unexpected HTTP status of:' . $status_code[0]); } if (!($xml = strstr($response, '&lt;?xml'))) { $xml = null; } echo $xml; </code></pre> <p><br /> Here is an example of the response: <br /></p> <pre><code> &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt; &lt;string xmlns=&quot;http://ws.example.com/resumes/&quot;&gt; &lt;Packet&gt; &lt;Errors /&gt; &lt;SessionToken&gt;1234567890&lt;/SessionToken&gt; &lt;/Packet&gt; &lt;/string&gt; </code></pre> <p><br /> How can I extract variables from XML and assign them to PHP variable?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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