View Full Version : error in my javascript code
nikku
02-12-2008, 11:57 AM
hello everyone,
I am putting my script.
The problem I am facing is the my xmlobj object is getting null.
Any suggestion as to what might be happening?
var xmldoc;
if(window.ActiveXObject)
{
xmldoc= new ActiveXObject("Microsoft.XMLDOM");
}
else if(document.implementation && document.implementation.createDocument)
{
xmldoc= document.implementation.createDocument("","",null);
//xmldoc.overrideMimeType("text/xml");
}
else
{
alert("your browser cannot handle this script");
}
xmldoc.async="false";
// while(xmldoc.readyState !=4){};
xmldoc.load("backup.xml");
alert(xmldoc); //alert1
xmlobj=xmldoc.documentElement;
alert(xmlobj); //alert2
alert1 gives me an object.
alert2 gives me a null value and i am not able to read the xml file because of this any feedback or code correction required.
Thanks
Cheers!!!
A1ien51
02-12-2008, 03:26 PM
Sounds like you have an invalid XML file.
Ways to debug: http://radio.javaranch.com/pascarello/2006/09/12/1158096122600.html
Eric
nikku
02-13-2008, 05:21 AM
hello everyone,
I am putting my script.
The problem I am facing is the my xmlobj object is getting null.
Any suggestion as to what might be happening?
var xmldoc;
if(window.ActiveXObject)
{
xmldoc= new ActiveXObject("Microsoft.XMLDOM");
}
else if(document.implementation && document.implementation.createDocument)
{
xmldoc= document.implementation.createDocument("","",null);
//xmldoc.overrideMimeType("text/xml");
}
else
{
alert("your browser cannot handle this script");
}
xmldoc.async="false";
// while(xmldoc.readyState !=4){};
xmldoc.load("backup.xml");
alert(xmldoc); //alert1
xmlobj=xmldoc.documentElement;
alert(xmlobj); //alert2
alert1 gives me an object.
alert2 gives me a null value and i am not able to read the xml file because of this any feedback or code correction required.
Thanks
Cheers!!!
Thanks a lot for the reply.
But i dont think that there is a problem with invalid xml file becuse this code runs fine for me on ie 6. The problem comes in when i am using mozilla.
Any suggestions.
Cheers!!!
A1ien51
02-13-2008, 04:06 PM
Have you tried to open up the xml file directly in Mozilla? Does it open correctly? If it does, than you know there is probably an issue with the code. Just because it works in IE, does not mean the XML is 100% valid. You know how quirky browsers can be if you code a lot of JavaScript.
Personally I would use the XMLHttpRequest object to load the XML instead of the method you are using.
Eric
nikku
02-14-2008, 05:13 AM
Have you tried to open up the xml file directly in Mozilla? Does it open correctly? If it does, than you know there is probably an issue with the code. Just because it works in IE, does not mean the XML is 100% valid. You know how quirky browsers can be if you code a lot of JavaScript.
Personally I would use the XMLHttpRequest object to load the XML instead of the method you are using.
Eric
thanks a lot for the input.
Leaving the XMLHttpRequest option aside do you people find any more issues with above code of mine.
j3n0vacHiLd
02-15-2008, 03:54 PM
Try changing this line
xmlobj=xmldoc.documentElement;
into this
xmlobj=xmldoc.body;
and see if it makes any difference
The article at http://javascript.about.com/library/bliebug.htm has some interesting information regarding document.documentElement and document.body
nikku
02-18-2008, 05:06 AM
Try changing this line
xmlobj=xmldoc.documentElement;
into this
xmlobj=xmldoc.body;
and see if it makes any difference
The article at http://javascript.about.com/library/bliebug.htm has some interesting information regarding document.documentElement and document.body
Thanks a lot for the reply.
I will try out what you have suggested and get back to you.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.