xmlTree = function(path, handler){
this.obj = new XML();
this.obj.ignoreWhite = true;
this.obj.disableXML = true;
this.obj.XMLArray = this.xml = new XMLArray();
this.obj.onLoad = handler;
this.obj.load( path );
}
/*
| XMLArray by Max Ziebell
| http://worldoptimizer.com
| ziebell@worldoptimizer.com
|
| Use it at your own risk.
*/
// ----------------------------------------------------
// XMLArray (version)
// ----------------------------------------------------
$XMLArrayVersion = '1.1.8';
// ----------------------------------------------------
// XMLArray (constructor)
// ----------------------------------------------------
function XMLArray (name, value, attrib) {
this._name = name;
if (value <> undefined ) {
this._value = value;
}
if (attrib <> undefined) {
this._attributes = attrib;
} else {
this._attributes = new Object();
}
}
// ----------------------------------------------------
// PROTOTYPES (definitions)
// ----------------------------------------------------
//
// USAGE: xmlArrayContainer.executeSAX( saxTable );
//
XMLArray.prototype.executeSAX = function ( SAX ){
var len = this._childNodes.length;
for(var cc=0; cc<len; cc++ ) {
var child = this._childNodes[ cc ];
SAX[ child._name ]( child );
if ( child._childNodes <> undefined) {
child.executeSAX ( SAX );
}
}
}
// some usefull sample SAX functions
XMLArray.prototype.findValueByTag = function ( tagName ){
_root.___SAXresult___ = new Array(); // prepare (temp stack)
var SAX = new Object(); // prepare ( SAX Event)
SAX[tagName] = function (tag) { _root.___SAXresult___.push (tag._value) }; //
SAX Event
this.executeSAX ( SAX ); // execute
var result = _root.___SAXresult___; // relink
delete ( _root.___SAXresult___ ); // unlink
return result; // return
}
XMLArray.prototype.findNodeByTag = function ( tagName ){
_root.___SAXresult___ = new Array();
var SAX = new Object();
SAX[tagName] = function (tag) { _root.___SAXresult___.push (tag) };
this.executeSAX ( SAX );
var result = _root.___SAXresult___;
delete ( _root.___SAXresult___ );
return result;
}
XMLArray.prototype.findNodeParentByTag = function ( tagName ){
_root.___SAXresult___ = new Array();
var SAX = new Object();
SAX[tagName] = function (tag) { _root.___SAXresult___.push (tag._parent) };
this.executeSAX ( SAX );
var result = _root.___SAXresult___;
delete ( _root.___SAXresult___ );
return result;
}
// end samples
XMLArray.prototype.parseXML = function(tags, enableFirstLevel){
var arrayPtr = this;
var curr;
var i=0;
var max = tags.length;
while (i<max){
curr = tags[i];
if (curr.type == 1){
if (curr.value == "/"+arrayPtr._name){
arrayPtr = arrayPtr._parent;
}else{
if (enableFirstLevel) {
arrayPtr = arrayPtr.appendChild( new _root.XMLArray (curr.value) );
arrayPtr._attributes = curr.attrs;
} else {
this._name = curr.value;
this._parent = null;
this._attributes = curr.attrs;
enableFirstLevel = true;
}
if (curr.empty){
arrayPtr = arrayPtr._parent;
}
}
}else{
if (curr.type == 3){
if (!this.checkEmpty(curr.value)){
arrayPtr._value = curr.value;
}
}else{
if (curr.type == 6){
arrayPtr._value = curr.value;
}else{
if (curr.type == 4){
this._xmlDecl = curr.value;
}else{
this._docTypeDecl = curr.value;
}
}
}
}
++i;
}
}
XMLArray.prototype.cloneNode = function (rekursion , empthy) {
var tempXMLArray = new _root.XMLArray();
tempXMLArray._name = this._name;
if (not empthy) {
tempXMLArray._value = this._value;
tempXMLArray._attributes= this._attributes;
}
if (rekursion and this._childNodes <> undefined) {
//trace ('was here');
this.cloneNodeChilds (this, tempXMLArray, empthy);
}
return tempXMLArray;
}
XMLArray.prototype.cloneNodeChilds = function (source, target, empthy) {
var len = source._childNodes.length; // how many childs are there?
for (var cc=0; cc<len; cc++) {
var sourceChild = source._childNodes[cc];
var targetChild = target.appendChild( new _root.XMLArray ( sourceChild._name
) );
//trace ('cloned: '+targetChild._name)
if (not empthy) {
targetChild._value = sourceChild._value;
targetChild._attributes = sourceChild._attributes;
}
if ( sourceChild._childNodes <> undefined ) {
sourceChild.cloneNodeChilds ( sourceChild, targetChild, empthy );
}
}
}
XMLArray.prototype.appendChild = function ( node ) {
if ( this[ node._name ] == undefined ) {
this[ node._name ] = new Array();
}
if ( this._childNodes == undefined ) {
this._childNodes = new Array();
}
var len = this[ node._name ].length;
this[ node._name ][ len ] = node;
this[ node._name ][ len ]._parent = this;
this._childNodes.push ( this[ node._name ][ len ] );
return (this[ node._name ][ len ])
}
XMLArray.prototype.extractXML = function(){
var xmlObj = new XML();
var tempElement = xmlObj.createElement( this._name );
tempElement._attributes = this._attributes;
xmlObj.appendChild ( tempElement );
this.extractXMLChilds( xmlObj.lastChild);
return xmlObj;
}
XMLArray.prototype.extractXMLChilds = function( xmlObj ){
var len = this._childNodes.length;
for(var cc=0; cc<len; cc++ ) {
var child = this._childNodes[ cc ];
var tempXML = new XML();
var tempElement = tempXML.createElement( child._name );
tempElement._attributes = child._attributes;
xmlObj.appendChild ( tempElement );
if ( child._value <> undefined) {
var tempElement = tempXML.createTextNode( child._value );
xmlObj.lastChild.appendChild ( tempElement );
} else {
child.extractXMLChilds ( xmlObj.lastChild );
}
}
}
//--------------------------------------------------
// XMLnitro v 2.0
//--------------------------------------------------
// Branden J. Hall
// Fig Leaf Software
// October 1, 2001
//
// Thanks to Colin Moock for good whitespace info
//--------------------------------------------------
// This file simply replaces the built-in parseXML
// method. In doing so it increases the speed of
// XML parsing 70-120% (dependent on file size).
// In addition, the ignoreWhite property now works
// in all versions of the Flash 5 plugin and no
// just the R41/42 versions. In order to do such
// this parser removes all text from mixed content
// nodes (i.e. nodes that contain both child nodes
// and child text nodes). This code is Flash 5
// specific so it makes sure that the user has only
// a Flash 5 plugin.
//--------------------------------------------------
//-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
// modified by Max Ziebell to work with XMLArray
// don't use if you ain't
// using XMLArray... rather get the original
// from Branden J. Hall
//-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!
Object.version = getVersion().split(",");
Object.majorVersion = int(substring(Object.version[0],Object.version[0].length,
1));
Object.minorVersion = int(Object.version[2]);
if (Object.majorVersion >= 5){
_checkEmpthy_ = function(text){
var max = text.length;
var empty = true;
for (var i=0;i<max;++i){
if (ord(substring(text, i+i, 1))>32){
empty = false;
break;
}
}
return empty;
}
XMLArray.prototype.checkEmpty = _checkEmpthy_;
XML.prototype.checkEmpty = _checkEmpthy_;
XML.prototype.parseXML = function(str){
var treePtr = this;
var tags = new Array();
var textNode = null;
if (Object.minorVersion == 30){
this.status = ASnative(300, 0)(str, tags);
}else{
this.status = ASnative(300, 0)(str, tags, false);
}
if (this.status == 0){
var curr;
var i=0;
var max = tags.length;
if (!this.disableXML) {
//trace('was in XML branch');
if (this.ignoreWhite){
while (i<max){
curr = tags[i];
if (curr.type == 1){
if (curr.value == "/"+treePtr.nodeName){
treePtr = treePtr.parentNode;
}else{
treePtr.appendChild(this.createElement(curr.value));
treePtr = treePtr.lastChild;
treePtr.attributes = curr.attrs;
if (curr.empty){
treePtr = treePtr.parentNode;
}
}
}else{
if (curr.type == 3){
if (!this.checkEmpty(curr.value)){
treePtr.appendChild(this.createTextNode(curr.value));
}
}else{
if (curr.type == 6){
treePtr.appendChild(this.createTextNode(curr.value));
}else{
if (curr.type == 4){
this.xmlDecl = curr.value;
}else{
this.docTypeDecl = curr.value;
}
}
}
}
++i;
}
}else{
while (i<max){
curr = tags[i];
if (curr.type == 1){
if (curr.value == "/"+treePtr.nodeName){
treePtr = treePtr.parentNode;
}else{
treePtr.appendChild(this.createElement(curr.value));
treePtr = treePtr.lastChild;
treePtr.attributes = curr.attrs;
if (curr.empty){
treePtr = treePtr.parentNode;
}
}
}else{
if (curr.type == 3 || curr.type == 6){
treePtr.appendChild(this.createTextNode(curr.value));
}else{
if (curr.type == 4){
this.xmlDecl = curr.value;
}else{
this.docTypeDecl = curr.value;
}
}
}
++i;
}
}
}
// mod
if (this.XMLArray <> undefined) {
//trace('was in XMLArray branch');
this.XMLArray.parseXML ( tags, this.enableFirstLevel );
if (typeof(this.onLoadSAX) == 'object') {
this.XMLArray.executeSAX ( this.onLoadSAX );
}
}
}
}
}