XML Loops?

Hi,

I have this very simple XML file, but i am not able to get a suitable function to get this going.


<?xml version="1.0" encoding="ISO-8859-1"?>
<content>
    <firstcontent>
        <title>News 01</title>
        <desc>This is the first description, more content can follow anytime</desc>
    </firstcontent>    

    <secondcontent>
        <name>News 02</name>
        <desc>This is the second description, more content can follow anytime</desc>
    </secondcontent>    

    <thirdcontent>
        <name>News 03</name>
        <desc>This is the third description, more content can follow anytime</desc>
    </thirdcontent>    

    <fourthcontent>
        <name>News 04</name>
        <desc>This is the fourth description, more content can follow anytime</desc>
    </fourthcontent>    
</content>

As you can see, this is a very simple news feed, i have a set of 6 dynamic boxes that will have the text for the names and desc properties of each content of the XML file. So which means one text box will have “News 01” as it’s text, and the second text box will have “This is the first description, more content can follow anytime” as it’s text.

Coding this is ok, but i am sure that there can be a for loop that will iterate through this within a few lines of code. I am still coming to terms with XML.

This is the code in Flash that i have…


function loadXML(loaded) {
if (loaded) 
_root.ftext.text=this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
_root.ftext1.text=this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;
_root.stext.text=this.firstChild.childNodes[1].childNodes[0].firstChild.nodeValue;
_root.stext1.text=this.firstChild.childNodes[1].childNodes[1].firstChild.nodeValue;
}}
ftext.autosize=true;
ftext1.autosize=true;
ftext1.wordwrap=true;
stext1.autosize=true;
stext1.wordwrap=true;
xmlData = new XML(); 
xmlData.ignoreWhite = true; 
xmlData.onLoad = loadXML; 
xmlData.load("datafirst.xml");

I did try a for loop construct…


for (var n = 0; n<xmlData.firstChild.childNodes.length; n++) 

This above for loop gives me the whole structure, but i want to pick out the content and post them into the individual boxes in Flash. So you can see, that the code is pretty long and confusing, that’s why i look forward to a for loop, can anyone please help ?

Thanks…