Display XML Content in an HTML table


In this article, I will explain how to Display XML Content in an HTML table.It will demonstrate XML files, XML formatting and XML transformation. JavaScript used together with XML(AJAX). In the following example, we are going to parse an XML file ("test.xml"), and display the contents of each element as an HTML table row. Learn Display XML Content in an HTML table.

Find the code for Displaying XML Content in an HTML table




<html>
<body>

<script type="text/javascript">

var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","test.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;

document.write("<table border='1' cellspacing=0,cellpadding=2>");
var x=xmlDoc.getElementsByTagName("Emp");
for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("NAME")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("AGE")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table>");
</script>

</body>
</html>


Comments

Author: satyajee srivastava05 Oct 2012 Member Level: Silver   Points : 0

Hi rajesh
Give the Details Procedure.Its through An error



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: