<分区>
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;
}