0

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 ?

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

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.