[英]How to create html table by reading column values from an XMLfile
I have to create a table in an html file by reading column names from an XML file. 我必须通过从XML文件读取列名来在html文件中创建表。 I am using java, Wicket, JQuery etc..(No hard coding of column names in html file) any suggestions? 我正在使用Java,Wicket,JQuery等。(没有对html文件中的列名进行硬编码)有什么建议吗?
something like this? 这样的东西?
<html>
<body>
<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","cd_catalog.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.write("<table border='1'>");
var x=xmlDoc.getElementsByTagName("CD");
for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table>");
</script>
</body>
</html>
just grabbed from http://www.w3schools.com/xml/xml_to_html.asp 刚刚从http://www.w3schools.com/xml/xml_to_html.asp中获取
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.