/** * Utility XML Class extends native XML Object to add parsing functionality USAGE: var xml = new XMLObj(); var xmldata = new Object(); xml.onLoad = function(success) { if (success) { trace(xmldata); trace(this.object); } else { trace("error"); } }; xml.load("file.xml", xmldata); */ class com.tonp.utils.XMLObj extends XML { var stripRoot:Boolean = false; var guessType:Boolean = false; var _data:Object; var _onLoad:Function; var _resultObj:Object var xml:XML; // public function XMLObj() { super(); } public function load(fileName:String, resultObj:Object) { _resultObj = resultObj super.load(fileName); } function set onLoad(f:Function){ _onLoad = f; } function get onLoad(){ var _ths = this; return function(success){ if(success){ var d = _ths.makeObj(this); if (_ths.stripRoot) { d = d.root; } _ths._data = d; //console.log(d); if (_resultObj) { for (var i in _ths._data) { _resultObj[i] = _ths._data[i]; } } } _onLoad(success) } } public function getGuessType(input:String){ if (!isNaN(Number(input))){ var out:Number = Number(input); }else if(input.toLowerCase() == "false"){ var out:Boolean = false; }else if(input.toLowerCase() == "true"){ var out:Boolean = true; }else{ var out:String = input; } return(out); } public function makeObj(xObj:Object, obj:Object):Object { /*if (xObj == null) { xObj = this; }*/ if (obj == null) { obj = {}; } var a, c, nName, nType, nValue, cCount; //----- Add attributes to the object for (a in xObj.attributes) { obj[a] = xObj.attributes[a]; if (guessType){ if (a.substring(0,7) == "array__"){ var tA = obj[a].split(","); for (var i=0; i