views:

149

answers:

2

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

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.

i called it on an xml that looked like this:

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

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

A: 
var num:int = myXml.length();

Cheers,

Tyler Egeto
as i said in the post- i tried it already. well, it gives me 1 even with 2 children...
vasion
looks like it's counting your <xml> node, not your <picture> nodes. try myXML.children().length().
heavilyinvolved
+2  A: 

Try

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