2

到目前为止,我已经在这里尝试了几个示例,但似乎无法弄清楚如何使用 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>

我正在尝试将 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>';
}       
4

1 回答 1

3

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

$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();    
    }
于 2013-04-19T06:34:54.943 回答