如何通过PHP读取SOAP回复包络
发布时间:2020-12-13 13:53:58 所属栏目:PHP教程 来源:网络整理
导读:如何从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_id1234567/transaction_id error_code
如何从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; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |