
Код:
// Constructor
_global.XML_2_OBJECT = function(watchXML)
{
this.$xml = this.$root=this.$parent=new Object();
ASSetPropFlags(this, null, 1, 1);
if (watchXML != undefined) {
this._parse.apply(this, arguments);
}
};
// load
XML_2_OBJECT.prototype.load = function()
{
var loader = this._makeLoader(this);
arguments[0] = this._makeURL(arguments[0]);
loader.load.apply(loader, arguments);
};
// toString
XML_2_OBJECT.prototype.toString = function()
{
return this.$xml.toString();
};
XML_2_OBJECT.prototype.getValue = function()
{
return (this.$xml.firstChild.nodeType == 3 ? this.$xml.firstChild.nodeValue : undefined);
};
//return the nodeName
XML_2_OBJECT.prototype.getNodeName = function()
{
return this.$xml.nodeName;
};
/*************************************************/
// Private
/*************************************************/
XML_2_OBJECT.prototype._parse = function(node, parent)
{
this.$parent = parent;
if (node instanceof XML) {
this.$root = node;
node = node.firstChild;
} else {
this.$root = this.$parent.$root;
}
this.$xml = node;
this.attributes = node.attributes;
if (node.nodeType == 1 and node.firstChild.nodeType != 3) {
for (var childCounter = 0; childCounter<node.childNodes.length; childCounter++) {
var tempName = node.childNodes[childCounter].nodeName;
if (this[tempName] == undefined) {
this[tempName] = new Array();
this.length++
ASSetPropFlags(this[tempName], null, 1, 1);
}
this[tempName].push(new XML_2_OBJECT(node.childNodes[childCounter], this));
}
}
};
// reParse
XML_2_OBJECT.prototype._reParse = function()
{
this._cleanup();
this._parse(this.$xml, this.$parent);
};
XML_2_OBJECT.prototype._cleanup = function()
{
for (var found in this) {
delete (this[found]);
}
};
// make path
XML_2_OBJECT.prototype._makeURL = function(host)
{
if (this._online()) {
var nocache = (random(100000)+100000);
if (_global.sessionID != undefined) {
return host+"?sid="+_global.sessionID+"&nocache="+nocache;
} else {
return host+"?nocache="+nocache;
}
} else {
return host;
}
};
XML_2_OBJECT.prototype._online = function()
{
return (_root._url.subStr(0, 7) == "http://");
};
XML_2_OBJECT.prototype._makeLoader = function(target)
{
var loader = new XML();
loader.ignoreWhite = true;
loader.link = target;
loader.onLoad = function(ok)
{
if (ok) {
ASSetPropFlags(this.link, ["onLoad"], 1, 1);
this.link._cleanup();
ASSetPropFlags(this.link, ["onLoad"], 0, 1);
this.link._parse(this);
this.link.onLoad(true);
var header = this.link.attributes;
if (header.session != undefined) {
switch (header.session) {
case "timeout" :
case "end" :
if (_global.session != undefined) {
delete (_global.session);
_global.onSessionEnd(header);
}
break;
default :
_global.session = new Object();
_global.session.id = header.session;
_global.onSessionStart(header);
break;
}
}
} else {
this.link.onLoad(false);
}
};
return loader;
};
ASSetPropFlags(XML_2_OBJECT.prototype, null, 1, 1);
//******************************
menu = new XML_2_OBJECT();
menu.load("menu_en.xml");
menu.onLoad = function(ok)
{
if (ok) {
_root.test();
} else {
trace("error");
}
};