There are two reasons why
the code you posted will not
work with IE on the file system.
It does work with Firefox,
the following code works with
firefox and IE, as long as you
have note.xml on your desktop
with the htm file .
Code:
<html>
<body>
<h1>W3Schools Internal Note</h1>
<div>
<b>To:</b> <span id="to"></span><br />
<b>From:</b> <span id="from"></span><br />
<b>Message:</b> <span id="message"></span>
</div>
<script type="text/javascript">
var xmlhttp=false;
var ie = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
ie=true;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp=false;
}
}
if (!xmlhttp && window.createRequest) {
try {
xmlhttp = window.createRequest();
} catch (e) {
xmlhttp=false;
}
}
xmlhttp.open("GET","note.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
if(ie){
xmlDoc = new ActiveXObject ("microsoft.xmldom");
xmlDoc.loadXML(xmlhttp.responseText);
}
document.getElementById("to").innerHTML=
xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;
document.getElementById("from").innerHTML=
xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;
document.getElementById("message").innerHTML=
xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;
</script>
</body>
</html>And then the xml file named "note.xml":
The first reason is IE XMLHttpRequest won't
normally read the file system but ActiveXObject
will read file system.
Second IE only gives responseXML if the
file has XML headers , you get those
headers from server not file system.