Method One
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;
Method Two, JS loads the XML and displays it
<TITLE>JS loads XML and displays it </title>
<script type= "text/web Effects" >
var xmlhttp;
function GetData ()
{
To create an asynchronous object
Xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP");
Load server-Note no parameters
Xmlhttp.open ("Get", "XMLFile.xml", True)
Asynchronous Object Event Hooks
Xmlhttp.onreadystatechange=statechange;
Send request-no parameters
Xmlhttp.send (NULL);
}
function StateChange ()
{
if (xmlhttp.readystate==4 && xmlhttp.status==200)
{
Get all the returned data
var Data=xmlhttp.responsetext;
Show results
document.getElementById ("Divlist"). Innerhtml=data;
}
}
</script>
<body>
<table style= "Text-align:center" >
<tr>
<TD style= "Text-align:center" >
Display data obtained from an XML file </td>
</tr>
<tr>
<TD style= "Text-align:center" >
<input id= "button1" type= "button" value= "Get Table" onclick= "GetData ()"/></td>
</tr>
<tr>
<TD style= "Text-align:center" >
<div id= "Divlist" >
</div>
</td>
</tr>
</table>
</body>
Method Three supports Ff,ie6+,opera
function getxmldocument (file) {
var xmldoc;
try{//internet Explorer
xmldoc=new activexobject ("Microsoft.XMLDOM");
}
catch (e) {
try{/*firefox, Mozilla, Opera, etc.*/
xmldoc=document. Implementation.createdocument ("", "", null);
}
catch (e) {
alert (e.message);
return;
}
}
Xmldoc.async=false;
Xmldoc.load (URL);
Return xmldoc;
}