0

这是我的 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);
}
4

1 回答 1

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);
    }
}

希望这可以帮助!

于 2012-10-18T15:35:01.797 回答