如何通过PHP读取SOAP回复包络

如何从SOAP回复信封中读取error_code?我的 PHP版本是:5.2.0.
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
 <soap:Body>
  <Response xmlns="http://xxx.gateway.xxx.abcd.com">
   <return>
      <transaction_id>1234567</transaction_id>
      <error_code>109</error_code>    
   </return>
  </Response>
 </soap:Body>
</soap:Envelope>

我只需要读取error_code tag的值.其值为:109

我正在使用nusoap.我使用下面的代码但没有正常工作:

$response=htmlspecialchars($client->response,ENT_QUOTES);
$xml = simplexml_load_string($response); 
$ns = $xml->getNamespaces(true); 
$soap = $xml->children($ns['soap']); 
$error_code = $soap->body->children($ns['error_code']);
<?PHP 

$string = <<<XML
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
 <soap:Body>
  <Response xmlns="http://xxx.gateway.xxx.abcd.com">
   <return>
      <transaction_id>1234567</transaction_id>
      <error_code>109</error_code>    
   </return>
  </Response>
 </soap:Body>
</soap:Envelope>
XML;

$xml = new SimpleXMLElement($string); 
$xml->registerXPathNamespace("soap","http://www.w3.org/2003/05/soap-envelope");
$body = $xml->xpath("//soap:Body");
$error_code = (string)$body[0]->Response->return->error_code;
print_r($error_code); 
?>

要么

$xml = simplexml_load_string($string); 
 $error_code = (string)$xml->children('soap',true)
                            ->Body
                            ->children()
                            ->Response
                            ->return
                            ->error_code;

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...