views:

601

answers:

1

I am working in flex builder 3 with an XMLListCollection and have run into this (should be simple) parsing snag...

The XMLListCollection Data:

<data>
    <term name="NUMBERS">
        <alt_form name="1"/>
    </term>
    <term name="LETTERS">
        <alt_form name="A"/>
        <alt_form name="B"/>
        <alt_form name="C"/>
    </term>
</data>

The AS Function:

private function interateThroughXML(myList:XMLListCollection):void {
    for each (var node : XML in myList){
        trace(node.@name + " is my list item name");
        if (node.alt_form.@name != null) {
            trace(node.alt_form.@name + " is my list SUB item name");
        }
    }
}

The Output:

NUMBERS is my list item name
1 is my list SUB item name
LETTERS is my list item name
ABC is my list SUB item name

Note that the three subnode name values have been concatenated as "ABC". What do I need to do differently in order to capture the sub-item name values (A, B, and C) individually?

+1  A: 

You need to loop through the subnodes, too. Calling node.alt_form returns an XMLList, so iterate over that:

private function iterateThroughXML(myList:XMLListCollection):void {
    for each (var node : XML in myList){
        trace(node.@name + " is my list item name");
        for each (var subnode : XML in node.alt_form) {
            if (subnode.@name != null) {
                trace(subnode.@name + " is my list SUB item name");
            }
        }
    }
}
Matt Dillard
Why that didn't occur to me, I don't know... Your example plugged-and-played like a charm. Thanks a bunch Matt!
taipan