views:

148

answers:

1

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"
+2  A: 
node.path

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

Adrian
Is there a method to do this in reverse?
Vijay Dev
You mean like `node = document.at_css(path)` !?
Adrian