如何找到在AS3 XML的儿童人数 [英] how do I find the number of xml children in AS3

查看:249
本文介绍了如何找到在AS3 XML的儿童人数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让现场的文档说,这调用.lenght()XML对象

so live docs says this for calling .lenght() on an XML object

对于XML对象,该方法始终   返回整数1.长度()   XMLList类中的方法返回一个   1对XMLList对象值   仅包含一个值

For XML objects, this method always returns the integer 1. The length() method of the XMLList class returns a value of 1 for an XMLList object that contains only one value.

我把它叫做上,看起来像这样的XML:

i called it on an xml that looked like this:

<xml>
<picture>1</picture>
<picture>2</picture>
</xml>

我试图myXML.lenght(),它reallt返回1.如何让我的XML孩子的数量?

i tried myXML.lenght() and it reallt returned 1. how do i get the number of children in my xml?

推荐答案

尝试

var length:int = myXML.children().length();

此外,这是我使用,以确保孩子们真正的元素,而不仅仅是文本节点的方法。

Also, this is the method I use to make sure the children are really Elements, and not just Text Nodes.

    public static function getNumberChildElements(node:XML):int{
        var count:int = 0;
        for (var i:int=0; i<node.children().length(); i++){
            if (node.children()[i].nodeKind() == "element")
                count++;
        }
        return count;
    }

这篇关于如何找到在AS3 XML的儿童人数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆