直接在actionscript中获取叶节点

时间:2011-08-27 00:50:25

标签: actionscript-3 flex flex3

在复杂的XML中,我不知道叶节点名称/或它们的深度级别,我怎样才能直接提取XMLList变量中的所有叶节点?

感谢。

2 个答案:

答案 0 :(得分:0)

由于到目前为止还没有人回复,我假设没有简单的使用ECMA来实现通用XML ...并且将UDF作为唯一的选择(该函数将递归地继续检查是否有任何孩子们离开了 - 如果不是那么它的叶子。)

谢谢大家。

答案 1 :(得分:0)

        /**
         * function to check for the leaf nodes and return 
         * an XMLListCollection of leaf nodes. Give it 
         * your xml and an empty object of XMLListCollection for result.
         **/
        private function leafNodes(x:XML, retList:XMLListCollection):void {
            var xlist:XMLList;
            xlist = x.children();

            if (x.children().length() == 0) { // leaf node
                retList.addItem(x);
                return;
            }

            for each (var it:XML in xlist) 
                leafNodes(it, retList);

            return;
        }