function httpRequest(method,data,URL,Async) { if (Async == undefined) Async = false; var Http = null; try { Http = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { Http = new ActiveXObject("Microsoft.XMLHTTP"); } catch(oc) { Http = null; } } if (!Http && window.XMLHttpRequest) { Http = new XMLHttpRequest(); } if (Http == null) { alert("Your browser cannot handle this script,you can try IE or Firefox."); } Http.open(method,URL,Async); if (!Async) { Http.send(data); var response = Http.responseText; delete(Http); return response; } else { return Http; } } function XMLDatastore() { //类变量 var xmlDoc; var errorInfo; var listOfNodes; //类方法 this.init = init; this.createNew = createNew; this.loadFile = loadFile; this.loadXML = loadXML; this.rowCount = rowCount; this.colCount = colCount; this.getItem = getItem; this.getItemByName = getItemByName; this.insertRow = insertRow; this.addColumn = addColumn; this.setItem = setItem; this.setItemByName = setItemByName; this.getXML = getXML; this.getErrorInfo = getErrorInfo; this.destroy = destroy; function init() { // code for IE if (window.ActiveXObject) { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; } // code for Mozilla, Firefox, Opera, etc. else if (document.implementation && document.implementation.createDocument) { xmlDoc = document.implementation.createDocument('', '', null); xmlDoc.async=false; } else { alert('Your browser cannot handle this script,you can try IE or Firefox.'); } } function createNew() { root = xmlDoc.createElement("rows"); xmlDoc.appendChild(root); listOfNodes = xmlDoc.documentElement.childNodes; } function loadFile(fileName) { var result = false; xmlDoc.load(fileName); root = xmlDoc.getElementsByTagName(xmlDoc.childNodes[0].tagName)[0]; if (root.childNodes[1] == null) { listOfNodes = xmlDoc.documentElement.childNodes; } else { listOfNodes = root.getElementsByTagName(root.childNodes[1].tagName); } result = true; return result; } function loadXML(xml) { var result = false; if (navigator.appName.indexOf("Internet Explorer") == -1) { var parser=new DOMParser(); xmlDoc=parser.parseFromString(xml,"text/xml"); if (xmlDoc.documentElement) { result = true; listOfNodes = xmlDoc.documentElement.childNodes; } } else { xmlDoc.loadXML(xml); if(xmlDoc.parseError !=0) errorInfo = xmlDoc.parseError.reason; else { result = true; listOfNodes = xmlDoc.documentElement.childNodes; } } return result; } function rowCount() { return listOfNodes.length; } function colCount() { var cols = 0; if(rowCount()>0) cols = listOfNodes.item(0).childNodes.length; return cols; } function getItem(rowNo,colNo) { var node = listOfNodes.item(rowNo); node = node.childNodes.item(colNo); return node.text; } function getItemByName(rowNo,colName) { var node = listOfNodes.item(rowNo); var rowNodes = node.childNodes; var i; for(i=0;i"; xmlstr += ""; for (i=0; i"; if (node.text != undefined) { xmlstr += node.text; } else { xmlstr += node.textContent; } xmlstr += ""; } xmlstr += ""; } xmlstr += ""; return xmlstr; } function getErrorInfo() { return errorInfo; } function destroy() { delete(xmlDoc); } }