早上好。
我有下一个带有子子项的 xml 文件,我想读取它们以将数据填充到表中。现在,我知道如何以简单的方式使用子节点来完成它,但我真的不知道如何实现它来获取子子节点。
<Result>
<Record id="000231">
<AC_NPD/>
<Name>Company1</Name>
<AC_CPR>00003</AC_CPR>
<AC_ALM>00</AC_ALM>
<AC_FEC>12/01/2007</AC_FEC>
<AC_LNA ncols="6">
<Row>
<Column>000084</Column>
<Column>1.230</Column>
<Column/>
<Column/>
<Column/>
<Column/>
</Row>
</AC_LNA>
<AC_FSE>12/01/2007</AC_FSE>
<AC_AV/>
<AC_UFH ncols="3"/>
</Record>
</Result>
现在,我使用以下脚本在表格中绘制结果:
<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","xml/pruebas/resp2.asp",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.write("<table class='table table-striped table-condensed table-bordered' id='example'>");
document.write("<thead>");
document.write("<tr class='odd gradeX'>");
document.write("<th>Sale</th>");
document.write("<th>Name</th>");
document.write("<th>Date</th>");
document.write("<th>Date Sale</th>");
document.write("<th>Item</th>");
document.write("<th>Quantity</th>");
document.write("<th class='hidden-phone'>Price</th>");
document.write("<th class='hidden-phone'>Total</th>");
document.write("<th>Sale Item</th>");
document.write("<th>Button</th>");
document.write("</tr>");
document.write(" </thead>");
var x=xmlDoc.getElementsByTagName("Record");
for (i=0;i<x.length;i++)
{
document.write("<tr>");
document.write("<td>"); document.write("</td>");
document.write("<td>"); document.write(x[i].getElementsByTagName("Name")[0].childNodes[0].nodeValue); document.write("</td>");
document.write("<td>"); document.write(x[i].getElementsByTagName("AC_FEC")[0].childNodes[0].nodeValue); document.write("</td>");
document.write("<td>"); document.write(x[i].getElementsByTagName("AC_FSE")[0].childNodes[0].nodeValue); document.write("</td>");
document.write("<td>"); document.write(x[i].getElementsByTagName("AC_LNA")[0].childNodes[0].nodeValue); document.write("</td>");
document.write("<td>"); document.write("</td>");
document.write("<td>"); document.write("</td>");
document.write("<td>"); document.write("</td>");
document.write("<td>"); document.write("</td>");
document.write("<td> <a data-toggle='modal' class='btn' href='sale.asp?&number="); document.write(x[i].getElementsByTagName("AC_FEC")[0].childNodes[0].nodeValue); document.write("' data-target='#myModal'> My Sale </a> "); document.write(" </td>");
document.write("</tr>");
}
document.write("</table>");
</script>
因此,如果有人知道如何获取子子节点,我将不胜感激。
最好的祝福。