Dear all

I have this xml file datechanged.xml:

- <changedate>

In a Javascript file I have folowing code:

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") ;
xmlDoc.async="false" ;
xmlDoc.load("datechanged.xml") ;
xmlObj=xmlDoc.documentElement ;
sDate = xmlObj.childNodes(0).firstChild.text;
var chDate=new Date(sDate) ;
I alwas get this error:

xmlObj is null or is not an object

change new ActiveXObject("Microsoft.XMLDOM") ;

to new ActiveXObject("msxml2.DOMDocument") ;

thanks for the reply,
but the same error occurs even after your suggested change:

xmlObj is null or is not an object

you might also like to consider incorporating Firefox support with the XMLHttpRequest object.

thanks for the reply,
but this is above my comprehension...


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) {
} 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);

		var chDate=new Date(sDate);
}"GET", "datechanged.xml", true);

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");
//Code for Mozilla
else if (document.implementation && document.implementation.createDocument)
  alert('Your browser cannot handle this script');

function getmessage()


The second example works on both Firefox 1.0.5 and IE7.0

This article has been dead for over six months. Start a new discussion instead.