开发者

AS3 XML: Cant traverse Nodes

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 mist开发者_StackOverflowake m doing?

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

thanks :)


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.


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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜