Fighterfox
12-09-2010, 12:36 PM
I'm not sure where the XML forum is, but maybe this will do. It's actually a combination of HTML, XML, and JavaScript. But anyway...
I am new XML, and need a little help getting it to work in IE—my code below already works in Firefox and Opera (I haven’t checked Chrome or Safari yet). For the following simple XML file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<location>
<california>
<cityname>Oakland</cityname>
<description>Located east of San Francisco on San Francisco Bay</description>
</california>
</location>
And for the following JavaScript parsing code:
<script type="text/javascript">
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","test.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.write("<table border='1'>");
var x=xmlDoc.getElementsByTagName("california");
for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("cityname")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table>");
</script>
How do I get my XML file to display in IE? Are there any basic inconsistencies or errors in my code that I have not noticed which is why IE fails to show what Firefox does? Thanks.
I am new XML, and need a little help getting it to work in IE—my code below already works in Firefox and Opera (I haven’t checked Chrome or Safari yet). For the following simple XML file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<location>
<california>
<cityname>Oakland</cityname>
<description>Located east of San Francisco on San Francisco Bay</description>
</california>
</location>
And for the following JavaScript parsing code:
<script type="text/javascript">
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","test.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.write("<table border='1'>");
var x=xmlDoc.getElementsByTagName("california");
for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("cityname")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table>");
</script>
How do I get my XML file to display in IE? Are there any basic inconsistencies or errors in my code that I have not noticed which is why IE fails to show what Firefox does? Thanks.