XPath查询选择节点时,属性不存在? [英] Xpath query to select node when attribute does not exist?
问题描述
我想以选择一个特定的属性不存在的节点。我已经试过not()函数,但它不工作。是否有此问题的方法?
I want to select nodes for which a specific attribute does not exist. I've tried the Not() function, but it doesn't work. Is there a way for this?
例如:
以下XPath查询:
Example: The following Xpath query:
group/msg[not(@owner)]
如果检索的第一个节点,但不是第二之一。但是,这两个SketchPath(工具测试Xpath查询)和我的C#code认为2个节点都ok。
Should retrieve the first node but not the 2nd one. However, both SketchPath (tool to test Xpath queries) and my C# code consider that the 2 nodes are ok.
<group>
<msg id="EVENTDATA_CCFLOADED_XMLCONTEXT" numericId="14026" translate="False" topicId="302" status="translated" >
<text>Context</text>
<comment></comment>
</msg>
<msg id="EVENTDATA_CCFLOADED_XMLCONTEXT_HELP" numericId="14027" translate="False" topicId="302" status="translated" owner="EVENTDATA_CCFLOADED_XMLCONTEXT" >
<text>Provides the new data displayed in the Object.</text>
<comment></comment>
</msg>
</group>
事实上,not()函数正常工作,它只是我有其他条件和括号设定不正确。的 errare humanum EST 的
In fact the Not() function works correctly, it's just that I had other conditions and parentheses weren't set correctly. errare humanum est.
推荐答案
在一些老的,不太标准的XPath引擎,我不得不使用字符串长度(@attr)= 0
出于同样的原因。
In some old and not very standard XPath engine I had to use string-length(@attr)=0
for the same reason.
这篇关于XPath查询选择节点时,属性不存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!