Using Nokogiri, I would like to determine the name of the root element.
I thought that doing an XPath query for /
would do the trick but apparently that node name is "document"?
require 'nokogiri'
doc = Nokogiri::XML('<foo>Hello</foo>')
doc.xpath('/').first.name # => "document"
doc.xpath('/foo').first.name # => "foo"
How can I get the string "foo" for the root node name without knowing it ahead of time?
/*
should work:or using
Nokogiri::XML::Document#root
: