Glowhollow
Glowhollow

Reputation: 132

XML check Nodes Actionscript 3

i repost my question to keep it simple.

I have following XML-Data

<lang>
  <common>
    <newnode>testTagInput</newnode>
  </common>
  <common>
    <gameIds>
      <game5>testTagInput</game5>
    </gameIds>
  </common>
</lang>

as we see, i have 2 times common. Is it possible to return common.children() for both ?

i coded this...

var XMLTree:Array=["common","common.newnode","common","common.gameIds","common.gameIds.game5"]
        var XMLListNodes:XMLList = loadXML[XMLTree[0]].children();
        for each (var subnodes:XML in XMLListNodes)
        {
            trace (subnodes);
        }

Is it possible to return more than 1 node at a time ? How ?

Upvotes: 0

Views: 57

Answers (2)

xims
xims

Reputation: 1608

If you know the XML structure and know what to expect from the first and the second <common>, you can address them as

  • XMLListNodes.common[0].newnode
  • XMLListNodes.common[1].gameIds

Upvotes: 1

fsbmain
fsbmain

Reputation: 5267

That will give you level1 (first level of nesting) and level2 (all levels of nesting) children:

        var xml:XML = <lang>
            <common>
                <newnode>testTagInput</newnode>
            </common>
            <common>
                <gameIds>
                    <game5>testTagInput</game5>
                </gameIds>
            </common>
        </lang>

        var commonChildrenLevel1:XMLList = xml.common.*;
        trace( "level1:", commonChildrenLevel1.length() );

        var commonChildrenLevel2:XMLList = xml.common..*;
        trace( "level2:", commonChildrenLevel2.length() );

Output:

[trace] level1: 2
[trace] level1: 5

Where 2 are the children <newnode> and <gameIds> and 5 - <newnode>, <gameIds>, <game5> and two text nodes testTagInput and testTagInput

Upvotes: 1

Related Questions