views:

25

answers:

2

I am trying to extract nodes from an XMLList as follows:

this.txtDebug.appendText("\n\ntmpData Dump:\n");
this.txtDebug.appendText(tmpData.user);

var XMLUsers:XMLList = tmpData.user;

this.txtDebug.appendText("\n\nprinted thorugh for loop:\n");
for (var i:int = 0; i < XMLUsers.length(); i++)
{
    this.txtDebug.appendText(XMLUsers[i] + String(i) + "\n");
}

and this is the output I am getting:

tmpData Dump:
<user id="10" score="100"/>
<user id="20" score="200"/>
<user id="30" score="300"/>
<user id="40" score="400"/>
<user id="1000" score="500"/>

printed thorugh for loop:
0
1
2
3
4

I tried with String(XMLUsers[i]) and tried with for each loop, but couldnt get the XMLUsers[i] printed.. Can some1 tell me whats the mistake m doing?

and to get the score attribute I need to write like "XMLUsers[i].@score" right?

thanks :)

+1  A: 

XMLUsers[i] is not printed because every node is empty, contrary for example <user id="10" score="100">user10</user>. And you are right about getting score attributes.

Miha
cool :) tat helped... I thought I am not traversing the nodes, but m actually traversing empty nodes... thx for clearing it up :)
saiy2k
+1  A: 

1 - You can try toXMLString() to see each line : XMLUser[i].toXMLString()+" "+i+"\n";

2 - For the score yes use XMLUser[i].@score

Patrick
thx :-) It worked. I didnt actually want de XML to be strings, I just wanted to check whether I was traversing right and it helped for tat :)
saiy2k