使用 simplexml_load_string 进行 SOAP XML 解析
我正在尝试使用 simplexml_load_string
解析简单的 xml肥皂响应,但没有成功。我已经尝试了很多在其他问题中找到的方法但没有成功。
XML 是:
<?xml version="1.0" encoding="utf-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<m:F2bCobrancaRetorno xmlns:m="http://www.f2b.com.br/soap/wsbilling.xsd">
<sacado numero="0000000015">
<nome>Pedro Fernandes Steimbruch</nome>
<email>[email protected]</email>
</sacado>
<cobranca nosso_numero="0004912903" numero="0004912903" taxa_registro="0.00">
<nome>Pedro Fernandes Steimbruch</nome>
<email>[email protected]</email>
<url>http://www.f2b.com.br/Billing?id=eq5GuK</url>
</cobranca>
<log>OK </log>
</m:F2bCobrancaRetorno>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我想获取日志和 url 对象。
I'm trying to parse a simple xml soap response with simplexml_load_string
without success. I have already tried a lot of ways that I found in other questions without success.
The XML is:
<?xml version="1.0" encoding="utf-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<m:F2bCobrancaRetorno xmlns:m="http://www.f2b.com.br/soap/wsbilling.xsd">
<sacado numero="0000000015">
<nome>Pedro Fernandes Steimbruch</nome>
<email>[email protected]</email>
</sacado>
<cobranca nosso_numero="0004912903" numero="0004912903" taxa_registro="0.00">
<nome>Pedro Fernandes Steimbruch</nome>
<email>[email protected]</email>
<url>http://www.f2b.com.br/Billing?id=eq5GuK</url>
</cobranca>
<log>OK
</log>
</m:F2bCobrancaRetorno>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I want to get log and url objects.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能正在考虑这一点,但该 XML 文档使用名称空间。这就是 XML 标记中冒号的含义。理论上,文档中给出的 URI 告诉解析器在哪里可以找到该命名空间中元素的模式。要使用 simpleXml 执行此操作,您需要解析文件以获取该名称空间的 URI,或者在本例中只需对其进行硬编码,即“http://www.f2b.com.br/soap/wsbilling.xsd” 。然后将 URI 传递给 SimpleXml 对象的 Children() 方法。
在此示例中,$document 包含包含 SOAP 数据的 SimpleXML 对象。 $subDocument 是一个新的 SimpleXML 文档,其中包含文档中命名空间“m”中的元素。
由于有两个命名空间(SOAP_ENV 和 m),一个嵌套在另一个命名空间内,我不知道您是否必须先访问“SOAP-ENV”才能访问“m”,或者是否可以直接跳转到“m” ”。
本页对此进行了讨论。 http://www.sitepoint.com/simplexml-and-namespaces/
You may be accounting for it, but that XML document uses name spaces. That is what the colon in the XML tag means. The URIs given in the document tell the parser, in theory, where to find the schema for elements in that namespace. To do this with simpleXml you would need to parse the file to get the URI for that name space, or in this case simply hard code it, i.e. "http://www.f2b.com.br/soap/wsbilling.xsd". Then you pass the URI to the children() method of the SimpleXml Object.
In this example $document contains the SimpleXML object containing the SOAP data. $subDocument is a new SimpleXML document that contains the elements from document that are in the namespace "m".
Since there are two namespaces (SOAP_ENV and m), one nested inside the other, I don't know if you would have to access "SOAP-ENV" before you could access "m", or if you can jump straight to "m".
This page discusses it. http://www.sitepoint.com/simplexml-and-namespaces/