SOAP response to XML with SimpleXML

£可爱£侵袭症+ 提交于 2019-12-19 09:15:55

问题


I am trying to convert a SOAP response to XML.

SOAP has an envelop and a body

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

When I try to convert

$responseXML = simplexml_load_string($string);

I get

object(SimpleXMLElement)#20 (0) { } 

If I edit the $string as soap:Envelope and soap:Body I can get the XML.

What's wrong with :? Can not get XML.

I hope it's clear. Anyone?


回答1:


A SOAP message is already XML. The problem is that it has namespaces so you have to access it differently. (The part before the colon is the identifier for the namespace.)

Here (google cached copy) is an example of using namespaces with SimpleXML.
Here is a specific example for reading SOAP messages.




回答2:


SimpleXML requires special treatment for namespaced XML (ref.)



来源:https://stackoverflow.com/questions/2773497/soap-response-to-xml-with-simplexml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!