class REXML::Element

def root_node


Related: #root, #document.

e.root_node == e # => true
e = REXML::Element.new('foo')

returns +self+:
When the element has no ancestor elements,

e2.root_node == e0 # => true
e2.parent = e1
e2 = REXML::Element.new('baz')
e1.parent = e0
e1 = REXML::Element.new('bar')
e0 = REXML::Element.new('foo')

returns the most distant ancestor element:
When the element is not part of a document, but does have ancestor elements,

child.root_node == d # => true
top_element.root_node == d # => true
d.root_node == d # => true
child = top_element.first # => ...
top_element = d.first # => ...
d = REXML::Document.new('
')

in this example +a+ is document element and the root node is its parent:
Note that the root node is different from the document element;
returns the root node of the document.
When the element is part of a document,

Returns the most distant ancestor of +self+.

root_node -> document or element
:call-seq:
def root_node
  parent.nil? ? self : parent.root_node
end