一个元素在另一个默认命名空间中的XPath是什么?

3
我正在处理这个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>
      <StartProcessFileResponse xmlns="http://www.abbyy.com/RecognitionServer4_xml/RecognitionServer4.xml">
         <StartProcessFileResult>{B4815D0C-91F9-4BD3-BF2F-3A70E935AA7B}</StartProcessFileResult>
      </StartProcessFileResponse>
   </soap:Body>
</soap:Envelope>

我需要获取XPath路径到StartProcessFileResult元素,但是当我在在线XPath验证器中尝试此XPath时,没有匹配项:

/soap:Envelope/soap:Body/StartProcessFileResponse/StartProcessFileResult

我尝试了一小部分XPath,这个XPath /soap:Envelope/soap:Body 返回了 <body> 元素,但是当我进一步尝试使用这个XPath /soap:Envelope/soap:Body/StartProcessFileResponse 访问 StartProcessFileResponse 时,没有匹配项。
我做错了什么?
1个回答

3

StartProcessFileResult位于默认命名空间http://www.abbyy.com/RecognitionServer4_xml/RecognitionServer4.xml中。

使用XPath库的命名空间绑定功能,将命名空间前缀(例如rs)绑定到http://www.abbyy.com/RecognitionServer4_xml/RecognitionServer4.xml

然后,以下XPath将选择所请求的StartProcessFileResult

/soap:Envelope/soap:Body/rs:StartProcessFileResponse/rs:StartProcessFileResult

如果您无法绑定命名空间前缀,则可以改用local-name()函数。

/soap:Envelope/soap:Body/*[local-name()='StartProcessFileResponse']/*[local-name()='StartProcessFileResult']

但首选方法是创建并使用命名空间前缀绑定。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接