这是我的XML文件:
<cm>
<strategy_description>
<category name="Account">
<item name="tree">test1</item>
<item name="type">test2</item>
</category>
<category name="Account2">
<item name="tree">test1</item>
<item name="type">test2</item>
</category>
</strategy_description>
</cm>
我想输出这样的东西:
Account
tree: test1
type: test2
Account2
tree: test1
type: test2
我做到了这一点,并设法以XML格式跟踪输出所有类别和项目节点:
var categoryList:XMLList = xmlData.strategy_description.category;
for each(var category:XML in categoryList){
trace(category);
}
答案 0 :(得分:2)
您需要嵌套循环,例如:
var categoryList:XMLList = xmlData.strategy_description.category;
for each(var category:XML in categoryList)
{
trace(category.@name);
for each(var item:XML in category.item)
{
trace(" "+item.@name +": "+ item);
}
}
希望这有帮助!