views:

19

answers:

1

Hi All,

I've building an XML editor and am having a little trouble parsing XML files that are passed in.

At the moment I can only parse a certain depth of XML elements, and I was wondering how you could get the deepest XML element, because at the moment I have a series of for each loops that loop through xmlElem.children() but this only allows me to parse to a certain depth, so it's rather limited.

Any help appreciated!

Cheers, Harry.

+1  A: 

Sounds like a job for recursion http://en.wikipedia.org/wiki/Recursion_%28computer_science%29

This function will traverse the entire XML structure, regardless of its size/depth.

function parseChildren(parent:XML):void {
    for each(child:XML in parent.children()) {
        //do whaterver...

        if(child.children().length() > 0) {
             parseChildren(child);
        {
    }
}
Tyler Egeto
Ah thats brilliant, thank you very much! Exactly what I needed. Cheers :)
harrynorthover