2014-06-10 154 views
0

什么应该是xpath查询来选择属性att不存在的元素。xpath查询选择元素不存在的属性

<root> 
    <elem att='the value' /> 
    <elem att='the value' /> 
    <elem att='the value' /> 
    **<elem />** 
    <elem att='the value' /> 
    <elem att='the value' /> 
</root> 

我想更新属性att不存在的元素。

感谢

+0

重复 - http://stackoverflow.com/questions/362945/xpath-query-to-select-node - 当属性-并 - 不存在?RQ = 1 – st4hoo

回答

4

您可以使用[@att]来测试属性的存在,所以你只需要:

//elem[not(@att)] 

...以测试缺乏这种

Tested using xpathtester

1

此外,您还可以使用@*(的attribute::*abbreviated form)来表示任何属性。

对于任何属性,例如:

//elem[@*] 

没有任何属性例如:

//elem[not(@*)]