Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 XML,它可以像
<?xml version="1.0" encoding="utf-8"?> <testnode type="1">123</testnode>
或喜欢
<?xml version="1.0" encoding="utf-8"?> <othernode attrib="true">other value</othernode>
或者根节点可能完全出乎意料。(理论上任何东西。)我正在使用 REXML 来解析它。如何找出哪个 XML 节点是根元素?
xml = REXML::Document.new "<?xml version" #etc (or load from file) root_node = xml.elements[1] root_node_name = root_node.name