<xml id="Data" src="data.xml"></xml>
<xml id="xmlData">
<?xml version="1.0" ?>
<data>
<row>
<col1 />
<col2 />
<col3 />
</row>
</data>
</xml><body>
<input type="button" value="change" onclick='change()'><table id="tabName" datasrc="#xmlData">
<thead>
<tr>
<th>col1</th>
<th>col2</th>
<th>col3</th>
</tr>
</thead><tbody>
<tr>
<td><span datafld="col1" /></td>
<td><span datafld="col2" /></td>
<td><span datafld="col3" /></td>
</tr>
</tbody></table>
</body>
<script>
function change(){
//請在這裡寫代碼實現我的要求
alert(Data.XMLDocument.xml);
xmlData.XMLDocument.loadXML(Data.XMLDocument.xml);
}
</script>
<xml id="xmlData">
<?xml version="1.0" ?>
<data>
<row>
<col1 />
<col2 />
<col3 />
</row>
</data>
</xml><body>
<input type="button" value="change" onclick='change()'><table id="tabName" datasrc="#xmlData">
<thead>
<tr>
<th>col1</th>
<th>col2</th>
<th>col3</th>
</tr>
</thead><tbody>
<tr>
<td><span datafld="col1" /></td>
<td><span datafld="col2" /></td>
<td><span datafld="col3" /></td>
</tr>
</tbody></table>
</body>
<script>
function change(){
//請在這裡寫代碼實現我的要求
alert(Data.XMLDocument.xml);
xmlData.XMLDocument.loadXML(Data.XMLDocument.xml);
}
</script>
另外的DATA.xml文件的内容就是你的XML数据内容如:
<?xml version="1.0" encoding="gb2312"?> //这一句一定需要的,否则会出问题
<data>
<row>
<col1>65</col1>
<col2>hr</col2>
<col3>hssd</col3>
</row>
</data>
<body>
<input type="button" value="change" onclick='change()'>
<div id=showxml><table>
<tr>
<th>col1</th>
<th>col2</th>
<th>col3</th>
</tr>
</table>
</div>
</body>
<script>
function change(){
dataXML.src="data.xml";
showxml.innerHTML =
dataXML.transformNode(dataXSL.documentElement);
}
</script>
<XML id=dataXML src=""/>
<XML id=dataXSL>
<DIV xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<TABLE BORDER="0" CELLSPACING="1">
<TR>
<TD><STRONG>col1</STRONG></TD>
<TD><STRONG>col2</STRONG></TD>
<TD><STRONG>col3</STRONG></TD>
</TR>
<xsl:for-each select="/data/row">
<TR>
<TD><xsl:value-of select="col1"/></TD>
<TD><xsl:value-of select="col2"/></TD>
<TD><xsl:value-of select="col3"/></TD>
</TR>
</xsl:for-each>
</TABLE>
</DIV>
</XML>