2006/01/11 | Html引用xml数据的例子
类别(网页类学习笔记) | 评论(2) | 阅读(169) | 发表于 09:30


HTML文件:
<head>
<script type="text/javascript">
function testclick(field)
{
var row=field.rowIndex
xmldso_list.recordset.absoluteposition=row
td_title.innerHTML=xmldso_list.recordset("TITLE")
td_artist.innerHTML=xmldso_list.recordset("ARTIST")
td_year.innerHTML=xmldso_list.recordset("YEAR")
td_country.innerHTML=xmldso_list.recordset("COUNTRY")
td_company.innerHTML=xmldso_list.recordset("COMPANY")
td_price.innerHTML=xmldso_list.recordset("PRICE")
}
</script>
</head>
<table border="1" bgcolor="yellow">
<tr align="left"><th>Title: </th><td id="td_title"></td></tr>
<tr align="left"><th>Artist: </th><td id="td_artist"></td></tr>
<tr align="left"><th>Year: </th><td id="td_year"></td></tr>
<tr align="left"><th>Country:</th><td id="td_country"></td></tr>
<tr align="left"><th>Company:</th><td id="td_company"></td></tr>
<tr align="left"><th>Price: </th><td id="td_price"></td></tr>
</table>
<xml id="xmldso_list" src="cd.xml" ></xml>
<table datasrc="#xmldso_list" border="1">
<thead>
<tr align="left"><th>Title</th><th>Artist</th><th>Country</th><th>Company</th><th>Price</th><th>Year</th><th>AA</th></tr>
</thead>
<tr align="left" onClick="testclick(this)">
<td><span datafld="TITLE"></span></td>
<td><span datafld="ARTIST"></span></td>
<td><div datafld="COUNTRY"></div></td>
<td><div datafld="COMPANY"></div></td>
<td align="right"><div datafld="PRICE"></div></td>
<td><div datafld="YEAR"></div></td>
<td><div datafld="AA"></div></td>
</tr>
</table>

xml文件:


<?xml version="1.0" encoding="ISO-8859-1" ?>
<!-- Edited with XML Spy v4.2 -->
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
<AA>1985</AA>
</CD>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
<AA>1985</AA>
</CD>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
<AA>1985</AA>
</CD>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
<AA>1985</AA>
</CD>
</CATALOG>


0

评论Comments