Hi,
What you have works for me in IE7.0 - Which doesn't mean it will work in IE6, but I will presume it does and that you actually want it to work in Mozilla.
In which case, you need to use the XMLHttpRequest Object...
var xmlDoc = null;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
xmlDoc = new XMLHttpRequest();
if (xmlDoc.overrideMimeType) {
xmlDoc.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // IE
try {
xmlDoc = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
xmlDoc.onreadystatechange = function() {
if(xmlDoc.readyState==4) {
xmlObj = xmlDoc.responseXML.getElementsByTagName('changedate').item(0);
var sDate = xmlObj.getElementsByTagName('date').item(0).firstChild.data;
var chDate=new Date(sDate);
alert(chDate);
}
}
xmlDoc.open("GET", "datechanged.xml", true);
xmlDoc.send(null);
This doesn't work on my IE7.0 - But I'm assuming it won't matter much. I also consider this the cool way of loading XML data... I much less cool way of doing this is:
var xmlDoc
function loadXML()
{
//Code for IE
if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("datechanged.xml");
getmessage()
}
//Code for Mozilla
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.load("datechanged.xml");
xmlDoc.onload=getmessage
}
else
{
alert('Your browser cannot handle this script');
}
}
function getmessage()
{
alert(xmlDoc.getElementsByTagName('changedate').item(0).getElementsByTagName('date').item(0).firstChild.data);
}
loadXML();
The second example works on both Firefox 1.0.5 and IE7.0