Connecting Tech Pros Worldwide Help | Site Map

XML file load for FireFox

Newbie
 
Join Date: Sep 2007
Posts: 3
#1: Sep 8 '07
Hello,
I need some help to solve the following problem. I wrote some html/javascript code to read data from an XML file:

XML file:
<places>
<place year="2000" name="Amsterdam" />
<place year="2000" name="Amstelveen" />
</places>

html/javascript code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>XML Test
</title>
<style type="text/css">
</style>
<script language="JavaScript" type="text/javascript">

var xmlDoc;
function load () {
//for IE7
if (window.ActiveXObject) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = "false";
xmlDoc.onreadystatechange = IE_verify;
xmlDoc.load("places.xml");
var xmlObj = xmlDoc.documentElement;
Show (xmlDoc);
}
//for FF
else if (document.implementation && document.implementation.createDocument) {
xmlDoc = document.implementation.createDocument("","",null) ;
xmlDoc.async = false;
xmlDoc.onload = function (evt) {Show (xmlDoc);};
xmlDoc.load("places.xml");
}
}

function IE_verify(xmlDoc) {
// 0 Object is not initialized
// 1 Loading object is loading data
// 2 Loaded object has loaded data
// 3 Data from object can be worked with
// 4 Object completely initialized
if (xmlDoc.readyState != 4) {
return false;
} else {
return true;
}
}

function Show (xmlDoc) {
var places = xmlDoc.getElementsByTagName ("place");
var count = places.length;
var Place = new Array();
for (var i=0; i<count; i++) {
Place [i] = new Array (
places[i].getAttribute ("year"),
places[i].getAttribute ("name"));
document.writeln (Place[i][0]
+ ", " + Place[i][1]
+ "<br>");
}
}
</script>
</head>

<body onload="load()">
</body>
</html>

This runs for IE7 and FireFox nicely locally on my PC. However, if I upload it to my homepage, then only IE7 displays the data; there is no data displayed in FireFox, no errors on the FF error console.
Who knows what's wrong?
drhowarddrfine's Avatar
Expert
 
Join Date: Sep 2006
Posts: 5,561
#2: Sep 9 '07

re: XML file load for FireFox


I don't remember much from studying xml but if you are using the xmlns, don't you have to use the xml declaration on the first line? But then the problem would be that IE doesn't recognize xhtml.
Newbie
 
Join Date: Sep 2007
Posts: 3
#3: Sep 9 '07

re: XML file load for FireFox


Quote:

Originally Posted by drhowarddrfine

I don't remember much from studying xml but if you are using the xmlns, don't you have to use the xml declaration on the first line? But then the problem would be that IE doesn't recognize xhtml.

Yep, I tried the xml on the first line as well; makes no difference.
And the 'strange' thing is, that all (IE + FF) works well on local PC. IE7 works from the internet provider home-page correctly, FF doesn't :O(
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#4: Sep 19 '07

re: XML file load for FireFox


I'll move this thread to the XML forum where it belongs, ok?

kind regards,

Jos
Reply