2009-08-24 130 views

回答

108
//node[not(@*)] 

这就是XPath来选择文档中名为 “节点” 的所有节点没有任何属性。

+0

1的被挑选出 - 这就是更多的XPath-γ溶液。 :) – Tomalak 2009-08-25 08:24:09

+0

这很好,但它仍然能找到我们能做的任何事情吗? – 2016-04-14 07:57:48

+0

@MarekCzaplicki请参阅下面的答案来解决这种情况。 https://stackoverflow.com/questions/1323755/xpath-how-to-select-nodes-which-have-no-attributes/43910689#43910689 – pip 2017-05-11 08:49:16

21
//node[count(@*)=0] 

将选择所有<节点>零属性

3

为了解决马立克Czaplicki的评论和扩大答案

//node[not(@*) or not(string-length(@*))] 

....将选择零个属性或已是所有空属性的所有节点的元素。如果这只是一个特定的属性,你有兴趣,而不是所有的人,那么你可以使用

//node[not(@attribute1) or not(string-length(@attribute1))] 

...这将选择要么不具有的属性称为attribute1或全部节点元素其中attribute1属性为空。

即,以下元素将由任一这些XPath表达式

<nodes> 
    <node attribute1="aaaa"></node> 
    <node attribute1=""></node> <!--This one --> 
    <node attribute1="bbbb"></node> 
    <node></node> <!--...and this one --> 
</nodes> 
相关问题