我对使用 XPath 和 XQuery 还很陌生,我似乎无法弄清楚为什么我无法使用以下 XPath 语句从以下 XML 返回 OrderID:
//OrderID[1]/text()
为什么找不到
OrderID
或者比使用这个 XPath 更深入?//soap:Body
这是 XML:
<soap:Envelope xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<SubmitOnlineSearchResponse xmlns="http://eservices.diligenz.com/">
<SubmitOnlineSearchResult>
<return>
<orderInfo>
<OrderID>75124507</OrderID>
</orderInfo>
</return>
</SubmitOnlineSearchResult>
</SubmitOnlineSearchResponse>
</soap:Body>
</soap:Envelope>
最佳答案
因为OrderID
在http://eservices.diligenz.com/
命名空间。
如果您可以修改消息,请添加
xmlns:di="http://eservices.diligenz.com/"
至
soap:Envelope
连同其他命名空间声明并将您的 XPath 更改为//di:OrderID[1]/text()
如果您无法修改消息,请使用宿主环境的工具将命名空间前缀绑定(bind)到命名空间,然后绑定(bind)
di
至http://eservices.diligenz.com/
为了使上述 XPath 工作。
关于xml - XPath 不返回值的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30326460/