0.0
Low commit activity in last 3 years
No release in over a year
backtrack-xpath accepts a REXML::Element and returns the full XPath back to the root.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Introducing the Backtrack-xpath gem

If you need to find the Xpath to the current node in an XML document, try the Backtrack-xpath gem.

Example:

require 'backtrack-xpath'

xml =<<XML
<root>
  <a>
    <summary><n/><x1/><x2/></summary>
    <records>
      <b>
        <summary><y color='blue'/><y2/></summary>
        <records>
          <c><summary><n/></summary><records/></c>
        </records>
      </b>
      <b>
        <summary><y color='red'/><y2/></summary>
        <records>
          <c><summary><n/></summary><records/></c>
        </records>
      </b>

    </records>
  </a>
</root>  
XML

doc = Rexle.new xml
node = doc.root.element '//y'
puts BacktrackXPath.new(node).to_xpath #=> root/a/records/b/summary/y

Note: An id or class attribute will be used in the XPath to help identify the element if they exist in any of the elements.

gem backtrackxpath xpath html