/** * Dummy class, just for compare traditional XML parsing with E4X * * @author Shaoken (Stéphane Bebrone) * @link http://weblog.shaoken.be */ class AsXml { public static function main():Void { var gallery:XML = new XML("FoobarFoobar descFoobar1 descFoobar2 desc"); // do few manipulations on XML content trace(gallery.firstChild.childNodes[0].attributes.url); trace(gallery.firstChild.childNodes[1].firstChild.firstChild.nodeValue); // loops and verifications var nLength:Number = gallery.firstChild.childNodes.length; for(var i:Number = 0; i < nLength; i++) { var child:XMLNode = gallery.firstChild.childNodes[i]; if(child.attributes.url == "http://www.foo.com/foobar2.jpg") { trace(child.firstChild.firstChild.nodeValue); // Foobar2 desc } } // xml modifications var newNode:XMLNode = gallery.createElement("image"); var subNode:XMLNode = gallery.createElement("description"); var subNodeText:XMLNode = gallery.createTextNode("Foobar3 desc"); newNode.attributes.url = "http://www.foo.com/foobar3.jpg"; subNode.appendChild(subNodeText); newNode.appendChild(subNode); gallery.firstChild.appendChild(newNode); trace(gallery); } }