# Counting XML Nodes

**URL:** <https://forum.kirupa.com/t/counting-xml-nodes/294076>\
**Category:** Uncategorized\
**Created:** [August 7, 2009, 9:28pm UTC](https://forum.kirupa.com/t/counting-xml-nodes/294076 "2009-08-07T21:28:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spykes](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@Spykes](https://forum.kirupa.com/u/Spykes)\
**Post date:** [August 7, 2009, 9:28pm UTC](https://forum.kirupa.com/t/counting-xml-nodes/294076/1 "2009-08-07T21:28:39Z")

</div>

I’m creating a news rotator based on RSS feed XML. I would like to display the number of news items and which number is currently displaying as they rotate through the timer. (i.e. item 2 of 4)

I have been able to get the total number of items using the length() method, but I’m not sure how to reference each item. Do I need to actually append a node and assign a number or is there an easier way.

My code looks like this so far:

```php

var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();

xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("RSS.xml"));

function LoadXML(e:Event):void {
    xmlData = new XML(e.target.data);
    xmlLoader.removeEventListener(Event.COMPLETE, LoadXML);
    ParseNews(xmlData);
    //trace(xmlData.*.item.length());
}

function ParseNews(newsInput:XML):void{
    var NumItems:int = newsInput.*.item.length();
    var itemList:XMLList = newsInput.channel.item;
    trace(NumItems);
        
    for each (var itemElement:XML in itemList){
        trace(itemElement);
        //add code to number each new item
        //add code to create an news object instance
    }
}

```

Thanks for any help.
