Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An xpath query that returns all nodes with the id attribute set

I can make a query that returns a result set of nodes with their id set to a value I know. But I can't figure out how to get a result set of all nodes that have an id explicitly set.

like image 429
Tyson of the Northwest Avatar asked Jan 21 '26 08:01

Tyson of the Northwest


1 Answers

I can't figure out how to get a result set of all nodes that have an id explicitly set.

*[@id] will select all nodes with an [id] attribute:

The catch is that it will pick up nodes where id is present but is empty (i.e. id="")

If you want to ignore nodes with empty [id] attributes, use: *[@id!=""]

like image 89
zzzzBov Avatar answered Jan 23 '26 11:01

zzzzBov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!