0

What should be xpath query to select an element where the attribute att not present.

<root>
  <elem att='the value' />
  <elem att='the value' />
  <elem att='the value' />
  **<elem />**
  <elem att='the value' />
  <elem att='the value' />
</root>

I want to update element where attribute att not present.

Thanks

dirkk
  • 6,160
  • 5
  • 33
  • 51
sunder
  • 1,803
  • 4
  • 29
  • 50
  • duplicate - http://stackoverflow.com/questions/362945/xpath-query-to-select-node-when-attribute-does-not-exist?rq=1 – st4hoo Jun 10 '14 at 12:23

2 Answers2

5

You can use [@att] to test for the presence of an attribute, so you just need:

//elem[not(@att)]

... to test for the absence of it.

(Tested using xpathtester)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
1

Also, you can use @* (the abbreviated form of attribute::*) to represent any attribute.

With any attribute example:

//elem[@*]

Without any attribute example:

//elem[not(@*)]
Daniel Haley
  • 51,389
  • 6
  • 69
  • 95