// JavaScript Document
function XmlDataProvider() {
	this.async = "false";
	this.xmlDoc = null;
	
	//装载XML文件
	this.loadFile = function (file, async) {
		var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		if(this.loadFile.arguments.length>1){
			xmlDoc.async = async;
		}else{
			xmlDoc.async = this.async;	
		}
		if(xmlDoc.load(file)) {
			this.xmlDoc = xmlDoc;
			return xmlDoc;
		}else{
			return false;
		}
	}
	
	//装载XML字符串
	this.loadString = function (s) {
		var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		if(xmlDoc.loadXML(s)){
			this.xmlDoc = xmlDoc;
			return xmlDoc;				
		}else{
			return false;
		}
	}
	
	//获取XML root对象
	this.getRoot = function () {
		if(!this.xmlDoc) return false;
		return this.xmlDoc.documentElement;
	}
	
	//返回XMLDOC对象
	this.getXmlDoc = function () {
		return this.xmlDoc;
	}
	//将该XML的上面两层节点内容返回为二维数组
	//索引为节点名称
	this.toArrayTop2 = function () {
		if(!this.xmlDoc) return false;
		var arrTmp = new Array();	
		var root = this.getRoot();
		if(!root.hasChildNodes) return false;
		for(i=0;i<root.childNodes.length;i++){
			arrTmp[i] = XmlDataProvider.nodeToArray(root.childNodes[i]);
			//alert("arrTmp["+i+"]['Date'] = " + arrTmp[i]["Date"]);
		}
		return arrTmp;
	}
	
	

}

//将节点数据返回为一维数组
//如果该节点为空节点则返回false
//忽略节点属性
XmlDataProvider.nodeToArray = function (n) {
	if(!n) return false;
	if(n.childNodes[0].nodeName=="#text") {
		//alert(n.text);
		return n.text;
	}
	var arrTmp = new Array();
	for(j=0;j<n.childNodes.length;j++){
		var index = n.childNodes[j].nodeName.toString();
		arrTmp[index] = n.childNodes[j].text;	
		//alert(arrTmp[index]);
	}
	return arrTmp;
}















