Ralph Vugts
Ralph Vugts

Reputation: 425

Processing Soap response with PHP

I've tried several examples on here so far but just can't seem to figure out how to process this soap response with PHP 5.3:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soapenv:Body>
  <ns1:getAuthenticationTokenResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://earthquake">
   <getAuthenticationTokenReturn xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">1CFA9FF89E1F6E2AC62C4E5A689EED65F144B7E827C386A60836D97A76E0C49F47FCC94637AFADB8EAEDF3110955F2622AB334B92EBFC568E563662C2202E51157A4D9AABBFDD9941119CC8C96681B51EE453006C460B50C6104A5E07C84CE88</getAuthenticationTokenReturn>
  </ns1:getAuthenticationTokenResponse>
 </soapenv:Body>
</soapenv:Envelope>

I'm trying to get the getAuthenticationTokenReturn into a varaible but have not had much luck so far.

Here is my code so far:

$xml = simplexml_load_string($result);    
$xml->registerXPathNamespace('ns1','http://schemas.xmlsoap.org/soap/encoding/');
foreach ($xml->xpath('//ns1:getAuthenticationTokenResponse') as $item)
{
  echo 'Name: '.$item,'<br>';
}       

Upvotes: 2

Views: 960

Answers (1)

sandy
sandy

Reputation: 1158

Try this, i have tried and i got the token

$string = '<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soapenv:Body>
  <ns1:getAuthenticationTokenResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://earthquake">
   <getAuthenticationTokenReturn xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">1CFA9FF89E1F6E2AC62C4E5A689EED65F144B7E827C386A60836D97A76E0C49F47FCC94637AFADB8EAEDF3110955F2622AB334B92EBFC568E563662C2202E51157A4D9AABBFDD9941119CC8C96681B51EE453006C460B50C6104A5E07C84CE88</getAuthenticationTokenReturn>
  </ns1:getAuthenticationTokenResponse>
 </soapenv:Body>
</soapenv:Envelope>';

$xml = simplexml_load_string($string);
$xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
$xml->registerXPathNamespace('ns1', 'http://earthquake');

foreach ($xml->xpath('//ns1:getAuthenticationTokenResponse') as $item)    
    { 
       echo $item->asXML();    
    }

Upvotes: 3

Related Questions