xml - Flex XMLListCollection 迭代连接收集的值

标签 xml apache-flex actionscript-3 flex3 flexbuilder

我正在使用 XMLListCollection 在 Flex builder 3 中工作,并且遇到了这个(应该很简单)解析障碍...

XMLListCollection 数据:

<data>
    <term name="NUMBERS">
        <alt_form name="1"/>
    </term>
    <term name="LETTERS">
        <alt_form name="A"/>
        <alt_form name="B"/>
        <alt_form name="C"/>
    </term>
</data>

AS 函数:

private function interateThroughXML(myList:XMLListCollection):void {
    for each (var node : XML in myList){
        trace(node.@name + " is my list item name");
        if (node.alt_form.@name != null) {
            trace(node.alt_form.@name + " is my list SUB item name");
        }
    }
}

输出:

NUMBERS is my list item name
1 is my list SUB item name
LETTERS is my list item name
ABC is my list SUB item name

请注意,三个子节点名称值已连接为“ABC”。为了单独捕获子项名称值(A、B 和 C),我需要做哪些不同的事情?

最佳答案

您还需要循环遍历子节点。调用 node.alt_form 返回一个 XMLList,因此对其进行迭代:

private function iterateThroughXML(myList:XMLListCollection):void {
    for each (var node : XML in myList){
        trace(node.@name + " is my list item name");
        for each (var subnode : XML in node.alt_form) {
            if (subnode.@name != null) {
                trace(subnode.@name + " is my list SUB item name");
            }
        }
    }
}

关于xml - Flex XMLListCollection 迭代连接收集的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2283624/

相关文章:

xml - Spark Xml 读取包括文件名

xml - 项目构建错误 : Unknown packaging: bundle

javascript - html 页面中显示错误#2032

linux - 柔性 : How does the compiler know about dependencies?

actionscript-3 - 如何在actionscript-3中应用声音失真?

xml - 尝试解码嵌套 XML 时获取所有字段

apache-flex - Flex DataGridColumn 显示多行字符串数据

actionscript-3 - 识别Action Script 3中的声音

flash - Actionscript 3 中的相对 URL

php - 如何用php验证xml