使用 SimpleXML 对 XML 的 SOAP 响应 [英] SOAP response to XML with SimpleXML

查看:25
本文介绍了使用 SimpleXML 对 XML 的 SOAP 响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 SOAP 响应转换为 XML.

I am trying to convert a SOAP response to XML.

SOAP 有一个信封和一个正文

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>

当我尝试转换时

$responseXML = simplexml_load_string($string);

我明白

object(SimpleXMLElement)#20 (0) { } 

如果我将 $string 编辑为 soap:Envelopesoap:Body 我可以获得 XML.

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

: 有什么问题?无法获取 XML.

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

我希望它很清楚.有人吗?

I hope it's clear. Anyone?

推荐答案

SOAP 消息已经是 XML.问题是它有命名空间,所以你必须以不同的方式访问它.(冒号前的部分是命名空间的标识符.)

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

此处(google 缓存副本) 是将命名空间与 SimpleXML 结合使用的示例.
此处是读取 SOAP 消息的具体示例.

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

这篇关于使用 SimpleXML 对 XML 的 SOAP 响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆