>>Here's XML2AS as an AS2 static class for her pleasure.

Steve,

I've used a lot of XML parsers, and have never found one I've been fully
satisfied with. I've seen you post this a few times before, but I couldn
never get yours working right, so I thought I would try again.  I like
the simplicity and figure that will translate to speed if I can get it
working.  

So, this worked fine initially, then stopped working:

        trace(xmlObj.config[0].test[0].attributes.foo);

So I suspected maybe your parser had not finished.  I even tried putting
the rest of the code further down the timeline to be sure at frame 20,
but no luck.  How would you grab "Other text" from the XML?  I tried it
this way, as I would have expected it to work:

        trace(xmlObj.config[0].items[0].item[2])

Also tried:

        trace(xmlObj.config[0].items[0].item[2].nodeValue)

Either way is how I would expect it to work, but they just trace
"undefined".  Here is my code with comments where it breaks - Again, I
even tried putting the rest of the code further down the timeline, to be
sure your method had finished parsing, but it made no difference:

import com.stevensacks.data.XML2AS;  //imports fine
var myXML = new XML();
myXML.load("myXML.xml");
myXML.onLoad = xmlLoadHandler

function xmlLoadHandler (success){
        var xmlObj:Object = {};
        XML2AS.parse(myXML.firstChild, xmlObj);
        trace(myXML.firstChild) //traces fine
        trace(XML2AS) //traces fine
        trace(xmlObj.config[0].test[0].attributes.foo);  //undefined
        trace(xmlObj.config[0].items[0].item[2].nodeValue) //undefined
        var nodes:Array = xmlObj.config[0].items[0].item; 
        trace(nodes) // undefined
        var i:Number = nodes.length; while (i--) {
                trace(nodes[i]);
        }
}

/* myXML.xml file:
<config>
        <test foo="bar"/>
        <items>
                <item><![CDATA[Some text]]></item>
                <item><![CDATA[More text]]></item>
                <item><![CDATA[Other text]]></item>
        </items>
</config>

your class file:

class com.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;
        }
}
*/

Any ideas?

Jason Merrill
Bank of America  
Global Technology & Operations
Learning & Leadership Development 
eTools & Multimedia Team

_______________________________________________
Flashcoders@chattyfig.figleaf.com
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