php 使用 SimpleXML 对 XML 的 SOAP 响应
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2773497/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SOAP response to XML with SimpleXML
提问by ntan
I am trying to convert a SOAP response to XML.
我正在尝试将 SOAP 响应转换为 XML。
SOAP has an envelop and a body
SOAP 有一个信封和一个主体
<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 $stringas soap:Envelopeand soap:BodyI can get the XML.
如果我编辑$stringassoap:Envelope并且soap:Body我可以获得 XML。
What's wrong with :? Can not get XML.
怎么了:?无法获取 XML。
I hope it's clear. Anyone?
我希望很清楚。任何人?
回答by Guffa
A SOAP message isalready 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.)
SOAP 消息已经是XML。问题是它有命名空间,所以你必须以不同的方式访问它。(冒号前的部分是命名空间的标识符。)
Here (google cached copy)is an example of using namespaces with SimpleXML.
Hereis a specific example for reading SOAP messages.
此处(google 缓存副本)是将名称空间与 SimpleXML 结合使用的示例。
下面是一个用于读取 SOAP 消息的特定示例。

