Using REXML::previous_sibling

require 'rexml/document'
include REXML

doc = Document.new("<root><a>444</a><a>555</a></root>")
node = XPath.first(doc.root, "a[2]")

puts node.previous_sibling
#=> <a>444</a>

# or 
puts node.previous_element
#=> <a>444</a>

In REXML to fetch the element before the current element usemethod previous_sibling or previous_element.

Tags:
Source:
1611hrs.txt
Published:
08-06-2014 16:11