XML2AS is the best one I've found. It's also the fastest. I didn't write it, but I have included it in my package of data tools.

It creates String objects out of nodes and applies attributes and the names of the child nodes as array properties.

I have written about it on many occasions on Flashcoders. Search the archives and you'll find stuff. Here's the compacted version of the method converted to a static AS2 class (static functions recurse faster).


class net.stevensacks.data.XML2AS
{
    public static function parse(n, r) {
        var a, d, k;
        if (r[k=n.nodeName] == null) r = ((a=r[k]=[{}]))[d=0];
        else r = (a=r[k])[d=r[k].push({})-1];
        if (n.hasChildNodes()) {
            if ((k=n.firstChild.nodeType) == 1) {
                r.attributes = n.attributes;
                for (var i in k=n.childNodes) XML2AS.parse(k[i], r);
            } else if (k == 3) {
                a[d] = new String(n.firstChild.nodeValue);
                a[d].attributes = n.attributes;
            }
        }else r.attributes = n.attributes;
    }
};


_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to