Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying XML Data in HTML File

Status
Not open for further replies.

omarchao

Programmer
Jul 26, 2010
1
0
0
US
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>
 
To simplify the matter, you've to serve the page through a webserver. Is that your environment the application is used?!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top