Question

What's the fastest/one-liner way to print the current nodes xpath, or just "path/to/node", in Ruby with Nokogiri?

So this:


<nodeA>
    <nodeB>
        <nodeC/>
    </nodeB>
</nodeA>

to this (say we've gone down to nodeC by processing xml.children.each, etc...):

"nodeA/nodeB/nodeC"
Was it helpful?

Solution

node.path

You can find the full documentation of node here: http://nokogiri.rubyforge.org/nokogiri/Nokogiri/XML/Node.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top