Using XPath, how to select elements with a missing attribute

I would like to select all elements that have a specific attribute or do not have it at all:

//job[@salary<"100" or !@salary ] 

This code is not valid. Which one of? Thanks!

+6
xml xpath
source share
3 answers
 //job[@salary<"100" or not(@salary)] 

There is no operator in xpath. See http://www.w3schools.com/xpath/xpath_operators.asp

+8
source share
 //job[count(@salary) = 0] 

I think:)

+1
source share
 //job[@salary<"100" or count(@salary)=0] 

Tested here and works great.

+1
source share

All Articles