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

XML xpath union operator broken #8455

Closed
repomaa opened this issue Nov 7, 2019 · 5 comments
Closed

XML xpath union operator broken #8455

repomaa opened this issue Nov 7, 2019 · 5 comments

Comments

@repomaa
Copy link
Contributor

repomaa commented Nov 7, 2019

Following xpath will fail with an XML::Error although it's valid xpath:

require "xml"
doc = XML.parse("<foobar><foo></foo><bar></bar><baz></baz></foobar>")
doc.xpath_nodes("//(foo|bar|baz)")
@asterite
Copy link
Member

asterite commented Nov 8, 2019

It doesn't work either in Ruby's Nokogiri, which uses libxml2 under the hood too. Maybe it's a bug or a limitation of libxml2.

@asterite
Copy link
Member

asterite commented Nov 8, 2019

Using "//foo|//bar|//baz" works, though.

@Fryguy
Copy link
Contributor

Fryguy commented Nov 8, 2019

The xpath pipe operator only combines full expressions, not partial expressions as in your example. You can use or with other selectors inside of [] to achieve what you want though. See https://stackoverflow.com/questions/13013696/in-xpath-is-it-possible-to-use-the-or-operator-with-node-names for an example

EDIT clarification: this applies to XPath 1.0, and libxml2 only supports 1.0, not 2.0

@jhass
Copy link
Member

jhass commented Nov 8, 2019

See above, libxml2 only supports xpath 1.

@jhass jhass closed this as completed Nov 8, 2019
@bew
Copy link
Contributor

bew commented Nov 8, 2019

Maybe we could add a line in the doc saying that, as it's not something I'd think to look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants