使用PHP处理Soap响应

时间:2013-04-19 06:32:11

标签: php soap

到目前为止,我在这里尝试了几个例子,但似乎无法弄清楚如何使用PHP 5.3处理这个soap响应:

<?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>

我正在尝试将getAuthenticationTokenReturn变为可变,但到目前为止还没有多少运气。

到目前为止,这是我的代码:

$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>';
}       

1 个答案:

答案 0 :(得分:2)

试试这个,我试过了,我得到了令牌

$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();    
    }
相关问题