title: XML parsing with AS2
body: <p>I'm using an XMLparser class to convert XML into an object.</p>
  
  <p>The problem is that the XML I have contains a dot in the nodeName (estate_size.primary_room_area). This of course doesn't work since it uses the dot notation for the object path already.</p>
  
  <p>Some ideas, but have no idea how to do them:<br />
  -Replace the dot in the name somehow<br />
  -Change the name.<br />
  -Any better?</p>
  
  <p>I can't use the native childNodes and stuff, since the XML isn't always in the right order.
  I don't have access to edit the XML.
  <br /><br /></p>
  
  <p><b>Anyone have a solution to this?</b></p>
  
  <p><br /></p>
  
  <p>XML:</p>
  
  <pre><code>&lt;iad&gt;
    &lt;DataTag&gt;
      &lt;element id="0"&gt;
        &lt;changed_string&gt;2009-08-20T10:56:00Z&lt;/changed_string&gt;
        &lt;estate_price.price_suggestion&gt;2500000&lt;/estate_price.price_suggestion&gt;
        &lt;estate_size.primary_room_area&gt;117&lt;/estate_size.primary_room_area&gt;
      &lt;/element&gt;
    &lt;/DataTag&gt;
  &lt;/iad&gt;
  </code></pre>
  
  <p>AS2:</p>
  
  <pre><code>    var xml:XMLParser = new XMLParser();
  xml.loadXML("file.xml");
  xml.onXMLLoad = function () {
          _root.estate_size.text = xml.data.iad.DataTag.element[0].estate_size.primary_room_area;
  }
  </code></pre>
  
  <p>XMLparser:</p>
  
  <pre><code>//import net.za.mediumrare.xmlPackage.XMLParser;
  //var myObject:XMLParser = new XMLParser ();
  //myObject.loadXML ("content.xml");
  //myObject.onXMLLoad = function () {
  //  listAll (myObject.data);
  //};
  
  
  
  // IMPORTED DEPENDENCIES
  //
  import mx.utils.Delegate;
  import mx.events.EventDispatcher;
  //
  class XMLParser {
         //
         // PRIVATE PROPERTIES
         //
         private var xml:XML;
         public var data:Object;
         //
         //
         //
         public function get _xml():XML {
                 return xml;
         }
         public function set _xml(x:XML) {
                 xml = x;
         }
         public function get _data():Object {
                 return data;
         }
         public function set _data(o:Object):Void {
                 trace("ERROR - \"XMLParser\" _data property is read-only and connot be set.");
         }
         //
         // CONSTRUCTOR
         //
         public function XMLParser(s:String) {
                 initXML(s);
                 //data = new Object();
                 EventDispatcher.initialize(this);
         }
         //
         // PRIVATE METHODS
         //
         public function buildObject (n){
              var o = new String (n.firstChild.nodeValue), s, i, t;
          for (s = (o == "null") ? n.firstChild : n.childNodes[1]; s != null; s = s.nextSibling) {
              t = s.childNodes.length &gt; 0 ? arguments.callee (s) : new String (s.nodeValue);
              for (i in s.attributes) {
                  t[i] = s.attributes[i];
              }
              if (o[s.nodeName] != undefined) {
                  if (!(o[s.nodeName] instanceof Array)) {
                      o[s.nodeName] = [o[s.nodeName]];
                  }
                  o[s.nodeName].push (t);
              }
              else {
                  o[s.nodeName] = t;
              }
          }
          data=o;
          xml = new XML();
          return data;
      };
  
         private function initXML(s:String):Void {
                 if (s == undefined) {
                         xml = new XML();
                 xml.ignoreWhite = true;
                 } else {
                         xml = new XML(s);
                 xml.ignoreWhite = true;
                 }
                 xml.onLoad = Delegate.create(this, xmlOnLoad);
         }
         private function xmlOnLoad(success:Boolean):Void {
                 if (success) {
                         trace("SUCCESS - xml loaded successfully.");
                         //xml.ignoreWhite = true;
                         this.dispatchEvent({type:"onXMLLoad", target:this});
                 buildObject(xml);
                         this.onXMLLoad();
                 } else {
                         trace("ERROR - xml could not load");
                         return;
                 }
         }
         //
         // PUBLIC METHODS
         //
         public function loadXML(url:String):Void {
                 xml.load(url);
         }
         public function getBytesTotal():Number {
                 return xml.getBytesTotal();
         }
         public function getBytesLoaded():Number {
                 return xml.getBytesLoaded();
         }
         public function getPercentLoaded():Number {
                 return Math.floor((this.getBytesLoaded() / this.getBytesTotal()) * 100);
         }
  
         //
         // EVENTS
         //
         public function onXMLLoad():Void {
                 // onLoad proxy for internal xml object
         }
         public function onXMLParse():Void {
                 // called when xml is finished parsing
         }
         function addEventListener() {
                 // Used by EventDispather mixin
         }
         function removeEventListener() {
                 // Used by EventDispather mixin
         }
         function dispatchEvent() {
                 // Used by EventDispather mixin
         }
         function dispatchQueue() {
                 // Used by EventDispather mixin
         }
  //
  
  
  
  }
  </code></pre>