本文介绍了使用 XPath 选择没有命名空间的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个类似的 xml
I have a xml like
<root xmlns:ns1="http://foo">
<ns1:child1>Text</ns1:child1>
<ns1:child2>Number</ns1:child2>
</root>
现在我从不同的人那里得到了这个,所以例如第二个人向我发送了另一条具有相同结构的消息
Now I get this from different persons, so that for example person 2 sends me another message with the same structure like
<root xmlns:anotherNs="http://foo">
<anotherNs:child1>Another Text</anotherNs:child1>
<anotherNs:child2>Another Number</anotherNs:child2>
</root>
所以唯一的区别是命名空间的名称.如何使用一个 XPath 表达式为两个 xml 选择 child2 的内容?
So the only difference is the name of the namespace. How can I select the content of child2 for both xml's with one XPath expression?
诸如/root/child2"或//child2"之类的东西不起作用.
Something like "/root/child2" or "//child2" did not work.
推荐答案
使用 local-name()
函数如下:
Use the local-name()
function like so:
//*[local-name()='child2']
这篇关于使用 XPath 选择没有命名空间的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!