Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc for \ is imprecise #178

Closed
ashawley opened this issue Dec 1, 2017 · 0 comments
Closed

Doc for \ is imprecise #178

ashawley opened this issue Dec 1, 2017 · 0 comments

Comments

@ashawley
Copy link
Member

ashawley commented Dec 1, 2017

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant