[英]AS3 XML: Cant traverse Nodes
I am trying to extract nodes from an XMLList as follows: 我试图从XMLList提取节点,如下所示:
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? 我尝试了String(XMLUsers [i])并尝试了每个循环,但是无法获取XMLUsers [i]。some1可以告诉我我在做什么错误吗?
and to get the score attribute I need to write like "XMLUsers[i].@score" right? 并获取分数属性,我需要像“ XMLUsers [i]。@ score”这样写吗?
thanks :) 谢谢 :)
XMLUsers[i]
is not printed because every node is empty, contrary for example <user id="10" score="100">user10</user>
. 不打印XMLUsers[i]
因为每个节点都是空的,例如<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";
1-您可以尝试toXMLString()查看每一行: XMLUser[i].toXMLString()+" "+i+"\\n";
2 - For the score yes use XMLUser[i].@score
2-对于分数,请使用XMLUser[i].@score
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.