instance method REXML::Element#root

root -> REXML::Element[permalink][rdoc][edit]

self が属する文書のルート要素を返します。


require 'rexml/document'
doc = REXML::Document.new(<<EOS)
<root>
<children>
  <grandchildren />
</children>
</root>
EOS

children = doc.get_elements("/root/children").first
children.name # => "children"
children.root.name # => "root"
grandchildren = doc.get_elements("/root/children/grandchildren").first
grandchildren.name # => "grandchildren"
grandchildren.root.name # => "root"