Link to home
Start Free TrialLog in
Avatar of LazarusBlack
LazarusBlack

asked on

XML Javascript doesn't work in Safari - Please help.

New to XML in XHTML. Use it in ActionScript successfully all the time - but this is driving me nuts.

This code (below) works everywhere but Safari... Go ahead and cut and paste it and you'll see.

I can't find a solution in English. Been programming for 20 years, but I don't speak Computer Science - so looking for how this code needs to be updated to include the Safari DOM. I've read that the solution is a form of HTTPrequest somethine - but can't find any actual solution. Just a few notes of people bragging that they 'figured it out' - but had to rearrange their code to do it.

What is missing?


<html>
<body>
<script type="text/javascript">
	var xmlDoc=null;
	if (window.ActiveXObject){// code for IE
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	}else if (document.implementation.createDocument){// code for Mozilla, Firefox, Opera, etc.
		xmlDoc=document.implementation.createDocument("","",null);
	}else{
		alert('Your browser cannot handle this script');
	}
	
	if (xmlDoc!=null){
		xmlDoc.async=false;
		xmlDoc.load("http://www.echo-x.com/portfolio.xml");
 
		var x=xmlDoc.getElementsByTagName("ART");
		for (i=0;i<x.length;i++){
			document.write("<img border='0' src='http://www.echo-x.com/images/navbuttons/grid_"+x[i].getElementsByTagName("IMAGE")[0].childNodes[0].nodeValue + ".gif'>");
		}
	}
</script>
</body>
</html>

Open in new window

Avatar of Pawel Witkowski
Pawel Witkowski
Flag of Poland image

ASKER CERTIFIED SOLUTION
Avatar of jwmcpeak
jwmcpeak
Flag of United States of America 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
Avatar of LazarusBlack
LazarusBlack

ASKER

I tried both offered solutions and the Sarissa files didn't work:

http://www.echo-x.com/xmltest1.html

However, jwmcpeak's solution appears to work perfectly. THANKS!!!!!

I'm going to go back to Sarissa and try to figure out why that didn't work - but if you have a suggestion, please refer to the code below.


<html>
<head>
<script type="text/javascript" src="http://www.echo-x.com/scripts/sarissa/sarissa.js"> </script>
</head>
<body>
<script type="text/javascript">
	var xmlDoc = Sarissa.getDomDocument("http://www.echo-x.com/portfolio.xml","foo", null);  
	
	if (xmlDoc!=null){
		xmlDoc.async=false;
		xmlDoc.load("http://www.echo-x.com/portfolio.xml");
 
		var x=xmlDoc.getElementsByTagName("ART");
		for (i=0;i<x.length;i++){
			document.write("<img border='0' src='http://www.echo-x.com/images/navbuttons/grid_"+x[i].getElementsByTagName("IMAGE")[0].childNodes[0].nodeValue + ".gif'>");
		}
	}
</script>
</body>
</html>

Open in new window

I don't know what your XML schema looks like, but I assume you're not using a namespace. So try calling the getDomDocument() factory method without passing any parameters:
var xmlDoc = Sarissa.getDomDocument();
 
if (xmlDoc != null) {
    xmlDoc.async=false;
    xmlDoc.load("http://www.echo-x.com/portfolio.xml");
 
    var x = xmlDoc.getElementsByTagName("ART");
    for (i=0;i<x.length;i++){
        document.write("<img border='0' src='http://www.echo-x.com/images/navbuttons/grid_"+x[i].getElementsByTagName("IMAGE")[0].childNodes[0].nodeValue + ".gif'>");
    }
}

Open in new window