I have some data xml data that looks 开发者_JS百科like this
<root xsi:noNamespaceSchemaLocation="test1.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<configuration>
<CLICK/>
<KLT/>
<DETd/>
</configuration>
</root>
I get a list of the configurations using
var results:XMLList = xml.configuration.*;
Now I want to loop over the XMLList and output CLICK, KLT, DETd etc. but how in XML do I get the node name as such
XML:
<root>
<parentNode>
<childNode1>1</childNode1>
<childNode2>2</childNode2>
<childNode3>3</childNode3>
</parentNode>
</root>
All you need to do is use .name()
while iterating through parentNode
's children()
.
for(var i:int=0;i<xml.children()[0].children().length();i++)
{
var currentNode:XML = xml.children()[0].children()[i];
trace(currentNode.name());
}
//childNode1
//childNode2
//childNode3
More:
- http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XMLList.html
- http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XML.html
Just use the name as the accessor.
for each (var prop:XML in xml.configuration.*)
{
trace(prop.name());
}
You had xml.configuration.*
listing what was needed, so you were half-way there. Just take each element as an XML in the iteration (with a for each loop).
You can use the name() method on any XML node, like so:
for each(var n:XML in results){
trace(n.name());
}
Will output:
CLICK
KLT
DETd
精彩评论