05 December 2008

XML 2 Object converter in AS 2.0

Hey mates, Here is a small class for converting a XML to Object. It will help you track XML data in a very simple way using dot(.) notation with each node's name. I'm elaborating it below with a sample XML:- XML File     <root>         <node1>Node 1 Text goes here</node1>         <node2 id="2">Node 2 data</node2>         <node3>             <sub_node3>Sub Node 3</sub_node3>         </node3>     </root> Flash Code var objDataXML:XML = new XML (); objDataXML.ignoreWhite = true; objDataXML.onLoad = onXMLLoad; objDataXML.load ("myXML.xml"); function onXMLLoad(success) {     if (success)     {         var m_objXMLData = new Object ();         XML2Object.parseXML (m_objXMLData, objDataXML.firstChild);         trace(m_objXMLData.node1.value);         trace(m_objXMLData.node2.attributes.id);         trace(m_objXMLData.node3.sub_node3.value);     } } Download the class file(XML2Object.AS) by clicking here.

0 comments:

Post a Comment