Tutorial :Using not() in XPath


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! :)


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

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


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



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


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

should work both.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »