I am trying to use an XML file for displaying data in HTML file. Strangely, the code works fine with Firefox and Safari, but doesn't display anything for Internet Explorer or Chrome.
Here is the code:
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
var xmlhttp = new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("get", "news.xml", false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
var x=xmlDoc.getElementsByTagName("POST");
for (i=0;i<x.length;i++)
{
document.write("<p class =" + "text-style-paragraph-5" + ">");
document.write("<a href = " + x.getElementsByTagName("URL")[0].childNodes[0].nodeValue + ">");
document.write("- ");
document.write(x.getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
document.write("</a></p>");
document.write("<p class =" + "text-style-paragraph-6" + ">");
document.write(x.getElementsByTagName("DATE")[0].childNodes[0].nodeValue);
document.write("</p>");
}
</script>
Here is the code:
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
var xmlhttp = new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("get", "news.xml", false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
var x=xmlDoc.getElementsByTagName("POST");
for (i=0;i<x.length;i++)
{
document.write("<p class =" + "text-style-paragraph-5" + ">");
document.write("<a href = " + x.getElementsByTagName("URL")[0].childNodes[0].nodeValue + ">");
document.write("- ");
document.write(x.getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
document.write("</a></p>");
document.write("<p class =" + "text-style-paragraph-6" + ">");
document.write(x.getElementsByTagName("DATE")[0].childNodes[0].nodeValue);
document.write("</p>");
}
</script>