[导入]解析XML并生成表格

点击“生成XML表格”的按钮后,在ID为“oDiv_createXmlTable”的DIV标签内显示一个表格,其内容是XML的数据

None.gif < XML  ID ="oXmlData" >
None.gif
< tab >
None.gif
< row >
None.gif
< col  name ="Col1" />
None.gif
< col  name ="Col2" />
None.gif
< col  name ="Col3" />
None.gif
row >
None.gif
< row >
None.gif
< col  name ="Col4" />
None.gif
< col  name ="Col5" />
None.gif
< col  name ="Col6" />
None.gif
row >
None.gif
< row >
None.gif
< col  name ="Col7" />
None.gif
< col  name ="Col8" />
None.gif
< col  name ="Col9" />
None.gif
row >
None.gif
tab >
None.gif
XML >
None.gif
< input  type ="button"  value ="生成XML表格"  onClick ="createXmlTable()" >
None.gif
< div  id ="oDiv_createXmlTable" > div >
None.gif
None.gif < script language = " JavaScript " >
ExpandedBlockStart.gifContractedBlock.gif
function  createXmlTable() dot.gif {
InBlock.gif
var HTML='';
InBlock.gif
var row=oXmlData.XMLDocument.getElementsByTagName('row');
InBlock.gif
var col=oXmlData.XMLDocument.getElementsByTagName('col');
InBlock.gifHTML
+='<table border><tr>';
ExpandedSubBlockStart.gifContractedSubBlock.gif
for(i=1;i<col.length+1;i++)dot.gif{
InBlock.gifHTML
+='<td>'+col[i-1].getAttribute('name')+'td>';
InBlock.gif
if(i%row.length==0 && i!=col.length) HTML+='tr><tr>';
ExpandedSubBlockEnd.gif}

InBlock.gifHTML
+='tr>table>';
InBlock.gifoDiv_createXmlTable.innerHTML
=HTML;
ExpandedBlockEnd.gif}

None.gif
script >
745865.html

suiqirui 2007-05-14 15:05 发表评论

文章来源: http://www.cnblogs.com/suiqirui19872005/archive/2007/05/14/745865.html

转载于:https://www.cnblogs.com/QiRuiNet-helloworld/archive/2007/06/17/786353.html

你可能感兴趣的:([导入]解析XML并生成表格)