如何找到在AS3 XML的儿童人数人数、儿童、XML

由网友(Man)分享简介:让现场的文档说,这调用.lenght()XML对象so live docs says this for calling .lenght() on an XML object对于XML对象,该方法始终返回整数1.长度()XMLList类中的方法返回一个1对XMLList对象值仅包含一个值For XML objects...

让现场的文档说,这调用.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;
    }
阅读全文

相关推荐

最新文章