1

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.

Oblivion
  • 7,176
  • 2
  • 14
  • 33
Jordan
  • 11
  • 2
  • See also: [***What is the difference between .// and //\* in XPath?***](https://stackoverflow.com/a/35608304/290085) – kjhughes Jun 16 '19 at 22:39
  • Asking questions on StackOverflow isn't really the best way to find out what specific language constructs mean. If you've looked at the spec or at a good book or tutorial and this has left you confused, then you should explain why it was unclear to you. If you haven't, then you're going about this the wrong way. – Michael Kay Jun 17 '19 at 08:11

2 Answers2

1

// 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.

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
0

// 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.

Nathan Surfus
  • 129
  • 1
  • 5