Use the length( ) method to count the number of elements found: trace( items.item.length( ) ); : Double dot « XML « Flash / Flex / ActionScript






Use the length( ) method to count the number of elements found: trace( items.item.length( ) );

 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
    //    To examine every element node with a particular node name, use a for each loop
        var items:XML = <items>
                          <item>
                            <name>Apple</name>
                            <color>red</color>
                          </item>
                          <item>
                            <name>Orange</name>
                            <color>orange</color>
                          </item>
                        </items>;
        
        for each ( var name:XML in items..name ) {
          trace( name );    
        }
    }
  }
}

        








Related examples in the same category

1.The double-dot operator works for any level of nesting
2.Using the Descendant Accessor (..) to make a deep dive to the data without worrying about the path.
3.pull all of the attributes from the entire XML document