2014-06-10 57 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(@*)]