有一个tonofexistingquestions关于PHP的SimpleXML和使用命名空间的处理XML。所有的我看了都取得了基本假设的问题:提前命名空间会是什么代码知道要包含在传入的SOAP请求。就我而言,我在SOAP请求中看到了不一致的名称空间。PHP的SimpleXML:在SOAP处理未知的命名空间请求
具体来说,我一直在努力实现web服务去跟Quickbooks Web Connector(PDF)和一些我见过像这样的例子请求:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dev="http://developer.intuit.com/">
<soapenv:Header/>
<soapenv:Body>
<dev:authenticate>
<dev:strUserName>username</dev:strUserName>
<dev:strPassword>password</dev:strPassword>
</dev:authenticate>
</soapenv:Body>
</soapenv:Envelope>
......以及一些是这样的:
<s11:Envelope
xmlns:s11='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:ns1='http://developer.intuit.com/'>
<s11:Header/>
<s11:Body>
<ns1:authenticate>
<ns1:strUserName>username</ns1:strUserName>
<ns1:strPassword>password</ns1:strPassword>
</ns1:authenticate>
</s11:Body>
</s11:Envelope>
...或这个:
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://developer.intuit.com/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns1:authenticate>
<ns1:strUserName>username</ns1:strUserName>
<ns1:strPassword>password</ns1:strPassword>
</ns1:authenticate>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我明白使用XPath()选择ELE发言:,但假设你知道如何寻找的命名空间中,没有任何一致性的命名空间,我有一个很难搞清楚如何正确,程序选择处理节点的内容。
命名空间在这个应用程序中是完全不相关的 - 我可以通过正则表达式运行原始XML以便首先从<whatever:mytag>
中删除whatever:
?
是的!我将前缀理解为命名空间的快捷方式。具有讽刺意味的是,我实际上是在尝试过自己的解决方案之前,无法让xpath识别我定义的备用前缀。我一定是做错了事。我显然还没有完全理解Xpath。原谅新手跟进问题(在这一点上应该不会令人惊讶),但是如果我不一定知道紧接着身体的下一个标记是什么,我仍然可以通过通配符选择它,或者一个使用'/ soap:Envelope/child :: soap:Body'的轴? – beporter 2011-01-27 14:44:29