123 or how

Get node name using REXML

I have XML that could be like

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

or how

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

or the root of the node may be something completely unexpected. (Theoretically, nothing.) I use REXML to parse it. How can I find out which XML node is the root element?

+4
source share
1 answer
 xml = REXML::Document.new "<?xml version" #etc (or load from file) root_node = xml.elements[1] root_node_name = root_node.name 
+10
source

All Articles