php - 使用 PHP 以不同方式解析 SOAP 响应

标签 php soap nusoap

<分区>

Possible Duplicate:
How to parse SOAP response without SoapClient

我有一个简单的 nuSoap XML 响应:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <LoginResult xmlns="http://Siddin.ServiceContracts/2006/09">FE99E5267950B241F96C96DC492ACAC542F67A55</LoginResult>
    </soap:Body>
</soap:Envelope>

现在我正尝试按照此处的建议使用 simplexml_load_string 对其进行解析:parse an XML with SimpleXML which has multiple namespaces在这里:Trouble Parsing SOAP response in PHP using simplexml ,但我无法让它工作。

这是我的代码:

$xml = simplexml_load_string( $this->getFullResponse() );
$xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
$xml->registerXPathNamespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$xml->registerXPathNamespace('xsd', 'http://www.w3.org/2001/XMLSchema');

foreach($xml->xpath('//soap:Body') as $header) {
    var_export($header->xpath('//LoginResult')); 
}

但我仍然只得到这个结果:

/* array ( )

我做错了什么?或者我想了解什么简单的事情?


DOM 的工作最终结果 MySqlError :

$doc = new DOMDocument();
$doc->loadXML( $response  );
echo $doc->getElementsByTagName( "LoginResult" )->item(0)->nodeValue;

SimpleXML 的工作最终结果 ndm :

$xml = simplexml_load_string( $response );
foreach($xml->xpath('//soap:Body') as $header) {
    echo (string)$header->LoginResult;
}

最佳答案

$doc = new DOMDocument();
$doc->loadXML( $yourxmlresponse );

$LoginResults = $doc->getElementsByTagName( "LoginResult" );
$LoginResult = $LoginResults->item(0)->nodeValue;

var_export( $LoginResult );

关于php - 使用 PHP 以不同方式解析 SOAP 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12969735/

相关文章:

php - 如何摆脱主题窃取者?

php - 在 laravel 5 中将一个表复制到另一个表

xmlns :soap attribute of SOAP element

java - 是什么使得带有 portType 但没有绑定(bind)的 wsdl 文件正确?

php - 防止 PHP 脚本同时运行多次的最佳方法?

php - 在 php5 中通过 Soap 发送安全的 wse header

php - 如何处理 NuSoap 中的数组 ComplexType?

javascript - 带有 PHP 脚本的模式,将编辑特定数据的信息

php - 覆盖模块的 Yii 登录 URL

web-services - 更改 SOAP :address location in generated wsdl