anon
anon

Reputation:

Getting the XML root node name

I have 2 xml files and one function to parse them. The function has to know how to parse them according to the xml document root node name.

How can I get the root name?

Upvotes: 3

Views: 2767

Answers (3)

Brian Genisio
Brian Genisio

Reputation: 48127

Assuming you have this XML:

var xml:XML = <TheRootNode><someData /></TheRootNode>;

Then to get the root node, you just call name():

Alert.show(xml.name()); // Displays "TheRootNode"

Cheers!

Upvotes: 3

George Profenza
George Profenza

Reputation: 51837

You can try the name() or localName() methods:

var xml:XML = <root><child /></root>
trace(xml.name());
trace(xml.localName());

Upvotes: 5

Patrick
Patrick

Reputation: 15717

use the name function of the XML object:

var xml1:XML=<foo></foo>
var xml2:XML=<bar></bar>
function parse(xml:XML):void{
    trace(xml.name())
}
parse(xml1) // trace foo
parse(xml2) // trace bar

Upvotes: 3

Related Questions