Note: There are several ways to determine if you are an IE browser or a non-ie browser, but here are just a few ways to use it:
1, parse the XML string, the way to get the XML object:
function Createxml (str) {
if (document.all) {//ie browser
var xmldoc = new ActiveXObject ("Microsoft.XMLDOM");
Xmldoc.async = false;
Xmldoc.loadxml (str);
return xmldoc;
}
else{//Non-IE browser
return new Domparser (). parsefromstring (str, "text/xml");
}
}
2. Parse the XML file and convert it to an XML object in the following way:
/**
* Axmlfilename is the path name of the XML file
*/
function Getxmldoc () {
try{
if (window. ActiveXObject) {
xmldoc= new ActiveXObject ("Microsoft.XMLDOM");
Xmldoc.async = false;
isLoaded = Xmldoc.load (axmlfilename);
}
else if (document.implementation&& document.implementation.createDocument) {
try{
xmldoc = Document.implementation.createDocument (', ', ', null);
Xmldoc.async = false;
Xmldoc.load (Axmlfilename);
} catch (e) {
var xmlhttp = new window. XMLHttpRequest ();
Xmlhttp.open ("GET", Axmlfilename,false);
Xmlhttp.send (NULL);
xmldoc = Xmlhttp.responsexml;
}
}
else{
Alert ("Load data error");
}
}
catch (e) {
alert (e.message);
}
}
This article is from the "Pig Flying" blog, please be sure to keep this source http://jiyanle.blog.51cto.com/6932197/1529727