Ruby 使用REXML获取节点名称

Ruby 使用REXML获取节点名称,ruby,rexml,Ruby,Rexml,我有一个XML,它可以是 <?xml version="1.0" encoding="utf-8"?> <testnode type="1">123</testnode> 123 或者 <?xml version="1.0" encoding="utf-8"?> <othernode attrib="true">other value</othernode> 其他价值 或者根节点可能是完全意外的。(理论上说,什么

我有一个XML,它可以是

<?xml version="1.0" encoding="utf-8"?>
<testnode type="1">123</testnode>

123
或者

<?xml version="1.0" encoding="utf-8"?>
<othernode attrib="true">other value</othernode>

其他价值
或者根节点可能是完全意外的。(理论上说,什么都可以。)
我正在使用REXML解析它。我怎样才能找到根元素是什么XML节点?

XML=REXML::Document.new“谢谢。我的辩护是,它不在文档中。或者至少我找不到它。不,我也无法在文档中找到它-我最后不得不用谷歌搜索。
xml = REXML::Document.new "<?xml version" #etc (or load from file)
root_node = xml.elements[1]
root_node_name = root_node.name