Jordan
Jordan

Reputation: 11

Operator Xpath //* meaning

I would like to know what //* means in an xpath expression because I have two expression

//*[A or B]

and

//* [count(descendant::*)=1]

so I don't know what these expressions do.

Upvotes: 1

Views: 92

Answers (2)

Thomas Weller
Thomas Weller

Reputation: 59279

// means everywhere in the tree (starting from the root node and going any levels down). It 's different to / which starts at the root node but then operates on the next immediate level.

* is for an arbitrary element (opposed to @ which would be an attribute).

Things inside [ and ] are a condition. In your cases, the condition [A or B] is whether there's a child element A or a child element B. The condition count(descendant::*)=1 means that there is only one child, grandchild and the like.

Upvotes: 1

Nathan Surfus
Nathan Surfus

Reputation: 129

// means select all, and * means any element.

So //* means select all elements. Adding the [A or B], also makes sure that the element also has a child element named A or B.

Adding the count(descendant::*)=1, I believe ensures that the element only has a single descendant with any name.

Upvotes: 0

Related Questions