Parsing SOAP response with PHP in different ways

Possible duplicate:
How to parse SOAP response without SoapClient

I have a simple nuSoap XML answer:

<?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> 

Now I am trying to simplexml_load_string it using simplexml_load_string , as suggested here: parse the XML using SimpleXML with several namespaces and here: Analyzing problems with SOAP in PHP using simplexml , but I can't get it working.

This is my code:

 $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')); } 

But I still only get this as a result:

 /* array ( ) 

What am I doing wrong? Or a simple thing that I do not understand in order to understand?


Working end result with DOM MySqlError :

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

The result of working with SimpleXML using ndm :

 $xml = simplexml_load_string( $response ); foreach($xml->xpath('//soap:Body') as $header) { echo (string)$header->LoginResult; } 
+4
source share
2 answers
 $doc = new DOMDocument(); $doc->loadXML( $yourxmlresponse ); $LoginResults = $doc->getElementsByTagName( "LoginResult" ); $LoginResult = $LoginResults->item(0)->nodeValue; var_export( $LoginResult ); 
+15
source

What is wrong here is the simple support for the SimpleXMLs namespace. To get this node using an XPath expression, you will need to register a prefix for the default namespace and use it in the query, although the element does not have a prefix, for example:

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

However, there is really no need to use XPath to access this node, you can simply access it directly:

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

Source: https://habr.com/ru/post/1440722/


All Articles