Stackoverflow question raises a fair concern that the documentation for \ is ambiguous.
https://stackoverflow.com/questions/47593308/xml-xpath-search-excludes-parent-node-but-recursive-search-doesnt
Currently, the doc for \ reads:
Projection function, which returns elements of this sequence based
on the string that. Use:
this \ "foo" to get a list of all elements that are labelled with "foo";
\ "_" to get a list of all elements (wildcard);
ns \ "@foo" to get the unprefixed attribute "foo";
ns \ "@{uri}foo" to get the prefixed attribute "pre:foo" whose prefix "pre" is resolved to the namespace "uri".
The original poster, raised the following examples:
scala> <b>foo</b> \ "b"
res0: scala.xml.NodeSeq = NodeSeq()
scala> <b>foo</b> \\ "b"
res1: scala.xml.NodeSeq = NodeSeq(b)
The confusion is that element searches with \ only operate on the current element's children, while \\ operates on the self, as well.
Additionally, it's worth pointing out that putting @ in the search will find attributes on the current element, and not its children.
scala> <b a="c">foo</b> \ "@a"
res2: scala.xml.NodeSeq = c
Stackoverflow question raises a fair concern that the documentation for
\is ambiguous.https://stackoverflow.com/questions/47593308/xml-xpath-search-excludes-parent-node-but-recursive-search-doesnt
Currently, the doc for
\reads:The original poster, raised the following examples:
The confusion is that element searches with
\only operate on the current element's children, while\\operates on the self, as well.Additionally, it's worth pointing out that putting
@in the search will find attributes on the current element, and not its children.