Anderson
Anderson

Reputation: 101

AS3 XML Looping, grabbing attributes and children

Here is my XML file:

<cm>
    <strategy_description>
        <category name="Account">
            <item name="tree">test1</item>
            <item name="type">test2</item>
        </category>
        <category name="Account2">
            <item name="tree">test1</item>
            <item name="type">test2</item>
        </category>
    </strategy_description>
</cm>

I want to output something like this:

Account
tree: test1
type: test2
Account2
tree: test1
type: test2

I got this far and manage to trace output all category and item nodes in XML format:

var categoryList:XMLList = xmlData.strategy_description.category;
for each(var category:XML in categoryList){
    trace(category);
}

Upvotes: 0

Views: 2857

Answers (1)

danii
danii

Reputation: 5693

You'll need nested loops, for example:

var categoryList:XMLList = xmlData.strategy_description.category;

for each(var category:XML in categoryList)
{
    trace(category.@name);

    for each(var item:XML in category.item)
    {
        trace("  "+item.@name +": "+ item);
    }
}

Hope this helps!

Upvotes: 2

Related Questions