xml Xpath:根据条件选择节点(使用 local-name())
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10813653/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xpath: select node based in a condition (with local-name())
提问by gisly
The question is quite silly, but I am completely stuck. I want to extract child nodes of a node based on a condition. The XML is as follows:
这个问题很愚蠢,但我完全被困住了。我想根据条件提取节点的子节点。XML 如下所示:
<a>
<aCode>aaa</aCode>
<aValue>bbb</aValue>
</a>
The expression is obvious: //a[aCode='aaa']
表达式很明显: //a[aCode='aaa']
But I can't get how I should change it if it is with namespaces and I've got to use local-name(). I've tested the following and it gives a parsing error:
但是,如果它与命名空间一起使用并且我必须使用local-name(). 我已经测试了以下内容,它给出了解析错误:
/*[local-name()='a'][[local-name()='aCode']='aaa']
Has anyone any idea of what I should do?
有没有人知道我应该做什么?
回答by choroba
You probably meant
你可能是说
//*[local-name()='a'][*[local-name()='aCode']='aaa']
回答by Cylian
Try this
尝试这个
/a/aCode[text()='aaa']
or
或者
//*[local-name() = 'aCode' and text() = 'aaa']
You have used //at wrong place.
你用//错地方了。
回答by karl368
This one work:
这一项工作:
//*[local-name()='a'][*[local-name()='acode' and text()='a2']]
and also this one:
还有这个:
//*[local-name()='a'][aCode[text()='a2']]

