Home > OS >  What is the difference between the following two xpath expressions?
What is the difference between the following two xpath expressions?

Time:07-22

If the expression //* is equivelant to the following expression /descendant-or-self::* and it returns all the elements in the xml document.

So why exists difference between

  1. /a//* (that does not returns a element)

and

  1. /a/descendant-or-self::* (which returns also a element)

Why /a//* does not returns also a element itself?

CodePudding user response:

// is actually short for /descendant-or-self::node()/ (note the trailing slash!), hence //* is actually short for /descendant-or-self::node()/* See https://www.w3.org/TR/1999/REC-xpath-19991116/#path-abbrev

So, from your example, /a//* actually means /a/descendant-or-self::node()/*, which is equivalent to /a/descendant::*, and is not the same as /a/descendant-or-self::*

  • Related