/* XML.makeObj Create a dot syntax object from an XML Object/File full XMLtree node recursion, Duplicate nodes collected as Array's > in which case node._type property set to == "array" > _type undefined in other cases =================================== Copyleft (-c-) J.Milkins - 2003-2004 http://www.mentalaxis.com */ XML.prototype.makeObj = function(xObj, obj) { //----- Initialise objects 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] } //----- Build child nodes for (c in xObj.childNodes) { nName = xObj.childNodes[c].nodeName; nType = xObj.childNodes[c].nodeType; nValue = xObj.childNodes[c].nodeValue; if (nType == 3) { obj._value = nValue; obj._type = 'text'; } if (nType == 1 && nName != null) { if (obj[nName] == null) { obj[nName] = this.makeObj(xObj.childNodes[c], {}); } else if (obj[nName]._type != 'array') { obj[nName] = [obj[nName]]; obj[nName]._type = 'array'; } if (obj[nName]._type == 'array') { obj[nName].unshift(this.makeObj(xObj.childNodes[c], {})); } } } // Return object return obj; }; XML.prototype.loadToObject = function(path, callback) { this.load(path); this.callback = callback; this.onLoad = function (success) { if (success){ callback(this.makeObj()); } else { callback(false); } } }