Two load XML document JS code

Source: Internet
Author: User

<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> two load XML document JS code </title>
<script language= "Web Effects" >
function Loadxml (filename) {
@mrthink. Net
var xmldoc = null;
if (window.activexobject) {//write to IE Department
xmldoc = new ActiveXObject ("Microsoft.XMLDOM");
Xmldoc.async = false;//This sentence, otherwise the IE will report that the data required to complete the operation is not available
Xmldoc.loadxml (filename);//This is used to load an XML string.
Xmldoc.load (filename);//If you are using an XML file.
}
Else
if (document.implementation && document.implementation.createdocument) {//webkit,geckos,op kernel
var xmlhttp = new Window.xmlhttprequest ();
Xmlhttp.open ("Get", filename, false);//type, filename, cache
Xmlhttp.send (NULL);
xmldoc = Xmlhttp.responsexml;
}
else {
xmldoc = null;
}
return xmldoc;
}

Method Two

var xmldoc;
Try{//ie
Create an empty Microsoft XML Document Object
Xmldoc=new ActiveXObject ("Microsoft.XMLDOM");
}catch (e) {
Try{//ff
To create an empty XML Document object
Xmldoc=document.implementation.createdocument ("", "", null);
}catch (e) {
alert (e.message);
}
}
try{
Turns off asynchronous loading, which ensures that the parser does not continue to execute scripts until the document is fully loaded
Xmldoc.async=false;
Load XML document
Xmldoc.load (Xml_file);
}catch (e) {
alert (e.message);
return false;
}
return xmldoc;


</script>

<body>
In principle, fully compatible loading XML functions. After my test are: ie6/7/8,ff (geckos), Chrome (WebKit), opera, did not install Safira, but her and chrome-like core, should be no problem.

</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.