Are there any XML Parsers for Ruby that fully support XPath 2.0?
Asked Answered
W

0

7

I need to see if a node exists within a particular XML document. If the node does not exist, then I would like to use another value. With XPath 1.0 this involves craziness using concat. With XPath 2.0, I can get it to work with:

if (boolean(path-to-preferred-node)) then path-to-preferred-node else default-to-other-node

We need to use XPath 2.0 for this which rules out Nokogiri.

Any help would be greatly appreciated.

Wrinkly answered 4/11, 2014 at 14:14 Comment(2)
I'm pretty sure all XML parses for Ruby are built on libxml2 which doesn't support XPath 2.0. There have been some people that started implementing XPath 2.0 but real life issues arose so it's never been finished. You'll have to do it the dirty way I'm afraidTyrr
@BenE I was hoping that wasn't the case. The dirty way really forces me down another path as there will be cases where I have to do a switch on 3-5 different values for a particular attribute's value... That would be beyond dirty to accommodate so many values.Wrinkly

© 2022 - 2024 — McMap. All rights reserved.