web analytics

How to check check for non-existing attribute or node in XPath?

Options

codeling 1599 - 6654
@2016-01-18 12:52:39

Check for non-existing attribute

In XPath 1.0, you could do:

//node[not(@attribute)]
//node[concat(@attribute, '') = ''
//node[not(boolean(@attribute))]

In XPath 2.0 and above, you could also do:

//node[not(exists(@attribute))]
@2016-01-18 12:57:05

Check for non-existing node

You can use the count function to count the node you are checking. If it do not exist, then the value of count will be 0:

count(//node-to-check) = 0

or you can call boolean function:

boolean(//node-to-check)

This returns true if "node-to-check" node exist and false if not.

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com