The following XPath query r...">

Fuzzy use // in XPath

Take a look at the following XML file:

<a>
  <b w="w">
    <b1 x="x" />
    <b2 y="y" />
  </b>
</a>

The following XPath query returns elements b1and b2:

/*/*//*

From this, I conclude what it //*means to select all elements that are descendants b , not includingb .

However, the XPath query returns the following attributes w, x, y:

/*/*//@*

So, from this I conclude what it //@*means to select all the attributes that appear in descendants b , includingb .

How it works? Does it work //differently for elements with attributes, or is there something I am missing?

+4
source share
2 answers

// not suitable for /descendant-or-self::node()/

/* .

, /*/*// <a> (child root), <b> ( <a> <b>), descendant-or-self::node(), .. <b>, <b1> <b2>.

<b>, <b1> <b2> /*/*//, .

/*/*//* . <b1> <b2> , <b>: <b1> <b2>.

/*/*//@* . <b>, <b1> <b2> , .

, //* , b, b.

, . " , b , b, ". " b, b", " b", .

+2

xpath.

// xpath xpath //descendant-or-self::node()/. xpath, . child.

child , - @ , attributes.

tre.

+2

Source: https://habr.com/ru/post/1599111/


All Articles