Nov
23
Converting AS3 XML to XMLNode Object
I recently needed to convert an XML object to an XMLNode object in Actionscript 3. It’s not exactly rocket science, but the way to do it is hard to track down via the tubes. Here’s how I did it:
var my_xml:XML = new XML("<foo><bar></bar><bar2></bar2></foo>");
var xmldoc:XMLDocument = new XMLDocument();
xmldoc.ignoreWhite = true;
xmldoc.parseXML(my_xml.toXMLString());
var my_xmlnode:XMLNode = xmldoc.firstChild;
And there you have it. my_xmlnode is now an XMLNode object containing the data of my_xml. I needed to do this while using an AS3 Library that required an XMLNode, but I wasn’t about to go AS2 style and construct the node one attribute at a time.
-Andrew