loadxmldoc.js文件内容
function createXMLDoc(){
var xmldoc;
try {
xmldoc = new ActiveXObject("Microsoft.XMLDOM");
if(!xmldoc) xmldoc = new ActiveXObject("MSXML2.DOMDocument.3.0");
} catch(e){}
if(!xmldoc) {
return null;
} else{
xmldoc.async = "false";
if(xmldoc.parseError.errorCode == 0 ) {
return xmldoc;
} else {
return null;
}
}
}
function loadXMLDoc(dname) {//文档 如books.xml
var xmlDoc=createXMLDoc();
xmlDoc.async = "false";
xmlDoc.load(dname);
return (xmlDoc);
}
function loadXMLString(text) {//字符串
var xmlDoc=createXMLDoc();
xmlDoc.async = "false";
xmlDoc.loadXML(text);
return (xmlDoc);
}
/*
实例
var root=xmlDoc.documentElement;
var node=xmlDoc.createElement("user");
node.setAttribute("name","厅地三有");
node.setAttribute("age","39");
root.appendChild(node);
var x=root.childNodes;
for (i=0;i{
alert("name: " + x[i].getAttribute("name")+" age:"+x[i].getAttribute("age"));
}
*/
阅读(1349) | 评论(0) | 转发(0) |