这里就来说说怎么用数据岛的方式把xml文件里的内容显示在html页面吧
先贴代码,这是xml文件,book.xml
<?xml version="1.0" encoding="utf-8"?>
<books>
<book id="0001" bookcategory="文艺" amount="150" remain="80"
discount="8.5">
<title>三国演义</title>
<author>罗贯中</author>
<publisher>文艺出版社</publisher>
<ISBN>0-764-58007-8</ISBN>
<price>80.0</price>
</book>
<book id="0002" bookcategory="文艺" amount="300" remain="180"
discount="8.7">
<title>红楼梦</title>
<author>曹雪芹</author>
<publisher>三秦出版社</publisher>
<ISBN>7805468397</ISBN>
<price>22</price>
</book>
<book id="0003" bookcategory="文艺" amount="200" remain="175"
discount="8.5">
<title>西游记(上下册)</title>
<author>吴承恩</author>
<publisher>人民文学出版社</publisher>
<ISBN>7020008739</ISBN>
<price>40.12</price>
</book>
<book id="0004" bookcategory="文艺" amount="300" remain="192"
discount="8.7">
<title>水浒传(上下册)</title>
<author>吴承恩</author>
<publisher>时代文艺出版社</publisher>
<ISBN>7538714014</ISBN>
<price>40.85</price>
</book>
<book id="0065" bookcategory="文学" amount="120" remain="86"
discount="8.0">
<title>外国文学史(亚非卷)</title>
<author>朱维之</author>
<publisher>南开大学出版社</publisher>
<ISBN>7-310-01122-8</ISBN>
<price>20</price>
</book>
<book id="0076" bookcategory="文学" amount="130" remain="84"
discount="8.0">
<title>20世纪欧美文学简史</title>
<author>李明滨</author>
<publisher>北京大学出版社</publisher>
<ISBN>7-301-04616-2</ISBN>
<price>21.8</price>
</book>
<book id="0098" bookcategory="文学" amount="140" remain="76"
discount="7.0">
<title>西方文艺理论名著教程(上)</title>
<author>胡经之</author>
<publisher>北京大学出版社</publisher>
<ISBN>7-301-00649-7</ISBN>
<price>24</price>
</book>
<book id="0012" bookcategory="文学" amount="210" remain="60"
discount="8.5">
<title>西方文艺理论名著教程(下)</title>
<author>胡经之</author>
<publisher>北京大学出版社</publisher>
<ISBN>7-301-00179-7</ISBN>
<price>23</price>
</book>
<book id="0036" bookcategory="文学" amount="100" remain="80"
discount="8.3">
<title>中国文学理论批判史教程</title>
<author>张少康</author>
<publisher>北京大学出版社</publisher>
<ISBN>7-301-04091-1</ISBN>
<price>25</price>
</book>
<book id="0018" bookcategory="计算机" amount="200" remain="100"
discount="8.2">
<title>计算机导论</title>
<author>丁跃潮</author>
<publisher>高等教育出版社</publisher>
<ISBN>7-04-014768-8</ISBN>
<price>19.7</price>
</book>
<book id="0218" bookcategory="计算机" amount="400" remain="300"
discount="8.5">
<title>程序设计基础</title>
<author>张杰敏主编</author>
<publisher>高等教育出版社</publisher>
<ISBN>7-04-012652-4</ISBN>
<price>17.6</price>
</book>
<book id="0318" bookcategory="计算机" amount="100" remain="60"
discount="8.0">
<title>数据结构与算法</title>
<author>王晓东编</author>
<publisher>高等教育出版社</publisher>
<ISBN>7-04-013204-4</ISBN>
<price>21.8</price>
</book>
<book id="0181" bookcategory="计算机" amount="250" remain="156"
discount="8.0">
<title>XML Web Service开发</title>
<author>微软公司著</author>
<publisher>高等教育出版社</publisher>
<ISBN>7-04-015825-6</ISBN>
<price>65.00</price>
</book>
<book id="0189" bookcategory="计算机" amount="230" remain="160"
discount="8.0">
<title>VB.NET程序设计语言</title>
<author>微软公司著</author>
<publisher>高等教育出版社</publisher>
<ISBN>7-04-013188-9</ISBN>
<price>86.00</price>
</book>
<book id="0028" bookcategory="计算机" amount="100" remain="90"
discount="7.5">
<title>JavaScript速成教程</title>
<author>Michael Moncur著</author>
<publisher>机械工业出版社</publisher>
<ISBN>7-111-09070-5</ISBN>
<price>28.00</price>
</book>
<book id="0074" bookcategory="计算机" amount="130" remain="78"
discount="7.8">
<title>软件工程Java语言实现</title>
<author>Slephen R.Schach</author>
<publisher>机械工业出版社</publisher>
<ISBN>7-111-06714-2</ISBN>
<price>51.00</price>
</book>
<book id="0109" bookcategory="计算机" amount="210" remain="160"
discount="8.0">
<title>人工智能</title>
<author>Nils J.Nilsson</author>
<publisher>机械工业出版社</publisher>
<ISBN>7-111-04738-6</ISBN>
<price>45.00</price>
</book>
<book id="0305" bookcategory="计算机" amount="115" remain="26"
discount="7.5">
<title>ASP开发实例</title>
<author>清汉计算机工作室</author>
<publisher>机械工业出版社</publisher>
<ISBN>7-980039-74-2</ISBN>
<price>53.00</price>
</book>
</books>
这是html文件,名字可以自己随便取的,哈~
InventoryTable.firstPage()>首页
InventoryTable.previousPage()>上一页
InventoryTable.nextPage()>下一页
InventoryTable.lastPage()>末页
四种方法,可以帮助实现分页的效果
<xml id="dsolnventory" src="book.xml"></xml> 这里的id,src一定要写
<td><span datafld="author"></span></td> datafld,就是写你要显示的节点名称
<!DOCTYPE html>
<html>
<head>
<title>查看软工1401班学生信息</title>
</head>
<body>
<xml id="dsolnventory" src="book.xml"></xml>
<h2>学生信息</h2>
<hr/>
<table id="InventoryTable" datasrc="#dsolnventory" datapagesize="5" border="1" cellpadding="5">
<thead>
<th>书名</th><th>类别</th><th>书号</th><th>作者</th><th>出版社</th><th>定价</th><th>剩余数量</th>
</thead>
<tr align="center">
<td><span datafld="title"></span></td>
<td><span datafld="bookcategory"></span></td>
<td><span datafld="ISBN"></span></td>
<td><span datafld="author"></span></td>
<td><span datafld="publisher"></span></td>
<td><span datafld="price"></span></td>
<td><span datafld="remain"></span></td>
</tr>
</table>
<hr/>
<button οnclick="InventoryTable.firstPage()">首页</button>
<button οnclick="InventoryTable.previousPage()">上一页</button>
<button οnclick="InventoryTable.nextPage()">下一页</button>
<button οnclick="InventoryTable.lastPage()">末页</button>
</body>
</html>