Parsing a SOAP response with PHP in different ways [duplicate]

五迷三道 提交于 2019-11-30 22:06:40
$doc = new DOMDocument();
$doc->loadXML( $yourxmlresponse );

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

var_export( $LoginResult );

What's going wrong here is SimpleXMLs poor default namespace support. In order to fetch that node using an XPath expression, you'd need to register a prefix for the default namespace and use it in the query, even though the element isn't prefixed, for example:

foreach($xml->xpath('//soap:Body') as $header) {
    $header->registerXPathNamespace('default', 'http://Siddin.ServiceContracts/2006/09');
    var_export($header->xpath('//default:LoginResult'));
}

However, actually there's no need to use XPath for accessing this node, you can simply access it directly:

foreach($xml->xpath('//soap:Body') as $header) {
    var_export($header->LoginResult);
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!