0
<item id=1>
  <name>item1</name>
  <price>30</price>
</item>
<item id=2>
  <name>item2</name>      
</item>

I need an xpath to select only items that DO NOT have price for .net.

Heba El-Fadly
  • 281
  • 1
  • 5
  • 17

1 Answers1

1

For your original question:

item[price]

will give you all item elements that have a price element child. This includes an empty <price/> so if you want to avoid matching

<item>
  <name>item3</name>
  <price></price>
</item>

then you need one of the following

item[price/text()]
item[normalize-space(price)]

For the inverse, to select only item elements that do not have a price, you can use

item[not(price)]
Ian Roberts
  • 120,891
  • 16
  • 170
  • 183