1

I have some data xml data that looks 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

3 Answers 3

7

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:

  1. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XMLList.html
  2. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XML.html
Sign up to request clarification or add additional context in comments.

Comments

1

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).

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.