Using not() in XPath

无人久伴 提交于 2020-08-24 05:06:27

问题


I would like how to use the "not" in XPath properly. I just can't seem to get it to work with attributes.

Say I have this expression: //*[@name = 'Bob'] It is valid, and will return all nodes that have a name attribute equaling 'Bob'.

Now if I want all nodes that have a name attribute that do not equal 'Bob', I need to use an XPath such as: //*[@name not(='Bob')] but this is invalid.

I have tried multiple combinations with not() being placed in a different order, but I can't seem to get this to work. Could someone please inform me how to use not() properly?

Also, does the order change when using elements instead of attributes? Such as: //name[text() = 'Bob']

Thanks! :)


回答1:


According to : http://msdn.microsoft.com/en-us/library/ms256086.aspx, have you tried

//*[@name != 'Bob']



回答2:


Try

 //*[@name != 'Bob']

or

  //*[not(@name = 'Bob')]

should work both.




回答3:


//*[@name and @name != 'Bob']


来源:https://stackoverflow.com/questions/3418470/using-not-in-xpath

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!