I am new and working with XML.
I have a number of xml files exist on the server, i want the html web page must provide me with the means to choose a single xml file and subsequently display this as a table on the same web page. A drop-down list box is to be used to present the list of available xml files to me. The drop-down list box contents must reflect the files presently available in the specific xml folder on the server
.
drop-down list box and table must be populated as ecessary using Ajax techniques.
so far i work out a basic code to display xml to html as a table, need direction or some help.
I have a number of xml files exist on the server, i want the html web page must provide me with the means to choose a single xml file and subsequently display this as a table on the same web page. A drop-down list box is to be used to present the list of available xml files to me. The drop-down list box contents must reflect the files presently available in the specific xml folder on the server
.
drop-down list box and table must be populated as ecessary using Ajax techniques.
so far i work out a basic code to display xml to html as a table, need direction or some help.
Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>XML to HTML</title>
</head>
<body>
<br />
<br />
<script>
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","books.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.write("<table border='2'>");
var x=xmlDoc.getElementsByTagName("book");
for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("author")[0].childNodes[0]. nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("last")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("genre")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("publish_date")[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>
Comment