一:解析 XML 文件
function loadXMLDoc(dname){
try{//InternetExplorer
xmlDoc = newActiveXObject("Microsoft.XMLDOM");
}
catch(e){
try{
xmlDoc= document.implementation.createDo cument("","",null);
}
catch{
alert(e.message);
}
}
try{
xmlDoc.async =false;
xmlDoc.load(dname);
return(xmlDoc);
}
catch(e){
return(null);
}
}
二:解析 XML 字符串
function loadXMLString(txt){
alert("js:"+txt);
try{ //Internet Explorer
xmlDoc = newActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.loadXML(txt);
return(xmlDoc);
}
catch(e){
try{//Firefox,Mozilla,Opera,etc
parser= new DomParser();
xmlDoc= parser.parseFormString(txt,"text/xml");
return(xmlDoc);
}
catch(e){
alert(e.message())
return(null);
}
}
}