数据岛把XML文档引入HTML页面
通过数据岛,可以把XML文档引入到HTML页面中。数据岛可以访问XML文件。
<xml src="xmldso.xml" id="xmldso" async="false"></xml>
(如上面代码,可把xmldso.xml文件载入一个叫"xmldso"的数据岛中。属性async="false"的作用是在HTML处理器开始处理XML数据以前,必须确保XML文档中的所有数据都被载入到内存中。)
两个文件放在IIS里IE浏览就可见效果,htm页读取xml内容并多种形式显示
----- xmldso.htm文件内容 -----
<html>
<head>
<script type="text/javascript">
function movenext()
{
x=xmldso_list.recordset
if (x.absoluteposition < x.recordcount)
{
x.movenext()
}
}
function moveprevious()
{
x=xmldso_list.recordset
if (x.absoluteposition > 1)
{
x.moveprevious()
}
}
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>
<body>
<xml src="xmldso.xml" id="xmldso_list" async="false"></xml>
<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>
<table datasrc="#xmldso_list" width="100%" border="1">
<thead>
<th>Title</th>
<th>Artist</th>
<th>Year</th>
</thead>
<tr align="left" onClick="testclick(this)">>
<td><span datafld="TITLE"></span></td>
<td><span datafld="ARTIST"></span></td>
<td><span datafld="YEAR"></span></td>
</tr>
</table>
<h>
<p>
Title:
<span datasrc="#xmldso_list" datafld="TITLE"></span>
<br />Artist:
<span datasrc="#xmldso_list" datafld="ARTIST"></span>
<br />Year:
<span datasrc="#xmldso_list" datafld="YEAR"></span>
</p>
<p>
<input type="button" value="Previous CD"
οnclick="moveprevious()" />
<input type="button" value="Next CD"
οnclick="movenext()" />
</body>
</html>
----- xmldso.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>
</CD>
<CD>
<TITLE>Hide your heart</TITLE>
<ARTIST>Bonnie Tyler</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>CBS Records</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1988</YEAR>
</CD>
<CD>
<TITLE>Greatest Hits</TITLE>
<ARTIST>Dolly Parton</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>RCA</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1982</YEAR>
</CD>
</CATALOG>