function string2xml(str) {
	if(window.ActiveXObject) {
		var xml=new ActiveXObject('Microsoft.XMLDOM');
		xml.async='false';
		xml.loadXML(str);
	} else {
		var parser=new DOMParser();
		var xml=parser.parseFromString(str,'text/xml');
	}
	return xml.documentElement;
}

function xml_data(node) {
	var node;
	var childs;
	var loop;
	var row;
	var total;
	var real;

	this.xml_query=function(node) {
		this.node=node;
		if(this.node.hasChildNodes) {
			this.childs=this.node.childNodes;
			this.total=this.node.childNodes.length;
			this.real=this.total;
			for(loop=0;loop<child_nodes.length;loop++) {
				if(child_nodes[loop].nodeName=='#text') this.real--;
				//if(child_nodes[loop].firstChild) {
				//	if(child_nodes[loop].firstChild.data=='\n') right_total--;
				//}
			}
		} else {
			this.childs=null;
			this.total=0;
			this.real=0
		}
		this.loop=0;
	}

	this.xml_rows=function() {
		return this.real;
	}

	this.xml_fetch=function() {
		this.row='';
		if(!this.childs) return false;
		while(!this.row && this.loop<=this.total) {
			if(this.childs[this.loop]) {
				if(this.childs[this.loop].nodeName!='#text') {
					this.row=this.childs[this.loop];
				}
			}
			this.loop++;
		}
		if(this.row && this.loop<=this.total) return true;
		else return false;
	}

	this.xml_get=function(element,arr) {
		if(!arr) arr=this.row;
		if(arr.hasChildNodes) {
			var cel=null,value=null,ret=null;
			var childs=arr.childNodes;
			for(var item=0;item<childs.length;item++) {
				if(childs[item].nodeName=='#text') continue;
				cel=childs[item].childNodes[0];
				if(cel.data) value=cel.data; else value=cel;
				if(childs[item].nodeName==element) return value;
				if(childs[item].hasChildNodes) {
					ret=this.xml_get(element,childs[item]);
					if(ret) return ret;
				}
			}
			return null;
		} else {
			return arr;
		}
	}

	this.xml_att=function(element,arr) {
		if(!arr) arr=this.row;
		else if(arr=='root') arr=this.node;
		var atts=null,value=null,ret=null;
		if(arr.attributes) {
			atts=arr.attributes;
			for(var loop=0;loop<atts.length;loop++) {
				if(atts[loop].name==element) {
					return atts[loop].value;
				}
			}
		}
		if(arr.hasChildNodes) {
			var childs=arr.childNodes;
			for(var item=0;item<childs.length;item++) {
				if(childs[item].nodeName=='#text') continue;
				ret=this.xml_att(element,childs[item]);
				if(ret) return ret;
			}
		}
		return null;
	}

	this.xml_fetch_array=function() {
		this.row='';
		while(!this.row && this.loop<this.total) {
			if(this.childs[this.loop]) {
				this.row=xml2array(this.childs[this.loop]);
			}
			this.loop++;
		}
		if(this.row && this.loop<this.total) return true;
		else return false;
	}

	this.xml_get_array=function(element,arr) {
		if(!arr) arr=this.row;
		if(typeof(arr)=='object') {
			var value=null,ret=null;
			for(var item in arr) {
				value=arr[item];
				if(item==element) return value;
				if(typeof(value)=='object') {
					ret=this.xml_get(element,value);
					if(ret) return ret;
				}
			}
			return null;
		} else {
			return arr;
		}
	}

	this.xml_seek=function(row) {
		this.loop=row;
	}

	this.xml_query(node);
}

function xml2array(node) {
	var array_data=new Array;
	if(typeof(node.nodeName)=='undefined' || !node.nodeName) return null;
	if(node.nodeName=='#text' && !node.firstChild) return null;
	array_data[node.nodeName]=new Array;
	if(node.attributes) {
		if(node.attributes.length>0) {
			for(var loop=0;loop<node.attributes.length;loop++) {
				if(typeof(node.attributes[loop])!='undefined' && typeof(node.attributes[loop].name)!='undefined' && typeof(node.attributes[loop].value)!='undefined') {
					array_data[node.nodeName][node.attributes[loop].name]=node.attributes[loop].value;
				}
			}
		}
	}
	var ret=new Array,count=0;
	if(node.firstChild && node.nodeName.indexOf('#')>-1) {
		if(node.firstChild.data && node.firstChild.data!='\n') {
		 	array_data[node.nodeName][count++]=node.firstChild.data;
			return array_data;
		}
	} else if(node.firstChild) {
		if(node.firstChild.data && node.firstChild.data!='\n') {
			if((node.hasChildNodes && node.childNodes.length>1) || (node.attributes && node.attributes.length>0)) {
				array_data[node.nodeName][count++]=node.firstChild.data;
			} else {
				array_data[node.nodeName]=node.firstChild.data;
			}
		}
	}
	if(node.hasChildNodes) {
		var childs_array=node.childNodes;
		for(var loop=0;loop<childs_array.length;loop++) {
			ret=xml2array(childs_array[loop]);
			if(ret) array_data[node.nodeName][count++]=ret;
		}
	}
	return array_data;
}
