Link to home
Start Free TrialLog in
Avatar of Fleurys
Fleurys

asked on

Can't load XML in IE8

Hi,

We just started testing IE8 on one of our sites, and I"m unable to get the XML to load. Any ideas would be appreciated.



Thanks much.

Bill Fleury
function loadXMLDoc(fname)
	{
		var xmlDoc;
		// code for IE
		if (window.ActiveXObject) {
  			xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  		}
		// code for Mozilla, Firefox, Opera, etc.
		else
	 	if (document.implementation && document.implementation.createDocument) {
  			xmlDoc=document.implementation.createDocument("","",null);
  		}
		else {
  			alert('Your browser cannot handle this script');
  		}
		xmlDoc.async=false;
		xmlDoc.load(fname);
		return(xmlDoc);
	}

Open in new window

Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Browsers prior to IE8 installed the msxml3
I am not sure since I have not checked, but maybe that has finally changed

you should no use
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
since that object has been replaced by a more modern variant over 10 years ago
use
xmlDoc=new ActiveXObject("Msxml2.DOMDocument");
instead and see what happens then

It is a shame that all these web examples out there have not been updated
that is why you find all these bad examples on the web
Avatar of Hans Langer
Hans Langer

Try this:
function createXMLDOM(){
	var ARR_ACTIVEX = ["MSXML4.DOMDocument","MSXML3.DOMDocument","MSXML2.DOMDocument","MSXML.DOMDocument","Microsoft.XmlDom"]
	var STR_ACTIVEX = "";
	var bFound = false;
	var oXMLDOM = null
	for (var i=0; i < ARR_ACTIVEX.length && !bFound; i++) {
	  try {
		 oXMLDOM = new ActiveXObject(ARR_ACTIVEX[i]);
		 oXMLDOM.async = false;
		 oXMLDOM.resolveExternals = false;
		 STR_ACTIVEX = ARR_ACTIVEX[i];
		 bFound = true
 
	  } catch (ex) {
		//alert(ex + ' - ' + ARR_ACTIVEX[i])
	  }
	} 
	
	if (!bFound){
		if (document.implementation &&  document.implementation.createDocument) {
			oXMLDOM = document.implementation.createDocument("","", null);				
		}else{
			alert('XMLDocument not supported')
		}
	}
	return oXMLDOM
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@gerente

did you actually have the above script working?
I briefly checked it and it doesn't work for me
I must admit that I had never seen "MSXML3.DOMDocument" and "MSXML4.DOMDocument"
used as a ProgID. No wonder, they don't seem to exist
I found the webreference.com article where you presumably copied the code from, since it is exactly what you posted, it is old and full of mistakes
If you are using it in production, I strongly suggest that you change the progID array as I suggested above
You will not notice that "MSXML3.DOMDocument" and "MSXML4.DOMDocument" don't exist,
because your scripts will work, always using msxml3, because of the try/catch
It is usefull ading some sort of comment or marker in your code that briefs you on which progID eventually is used,
for example in debug mode,
it helps you understand that the catch is catching errors you are not expecting
So, it is time for you to change the ProgID array in your programms (possibly add 4.0 in the mix)
and remember... 90% of the code examples out there or out dated or simply wrong

cheers

Geert
Avatar of Fleurys

ASKER

Thanks Gertone.
 I've tried using "Msxml2.DOMDocument" and it works perfectly (solved our problem).

Also, I'd like to say how much I appreciate having access to experts such as your self. On my own I could have spent many hours on this issue. Thanks again.