打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
XML数据岛中数据的编辑和添加
分类: w3c技术 21人阅读 评论(0) 收藏 举报

                                         XML数据岛中数据的编辑和添加

     通过上节的学习,了解了如何通过HTML来样式化的显示XML中的数据,下来尝试着利用数据岛来完成数据的编辑,添加。

来看用Javascript操作XMLDSO的方法:

      movePrevious().指向前一个数据项。

      moveNext().指向下一个数据项。

      moveFirst().指向第一个数据项。

      moveLast().指向最后一个数据项。

      addNew().增加一个数据项。而实际的xml中并没有增加任何数据。

    下面通过一个实例来说明:

第一步:写一个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>

第二步:新建一个显示book.xml的HTML文件.比如,book.html.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
 <title>HTML中的数据岛中的记录集</title>
</head>
<body>
<xml id="XMLdata" src="book.xml"></xml>      <!--引入xml数据源-->
<center><b><font size="3">HTML中的XML数据岛记录编辑与添加</font></b>
</center><hr/>
书名:<input type="text" datasrc="#XMLdata" datafld="title" size="25"><br/>
类别:<input type="text" datasrc="#XMLdata" datafld="bookcategory" size="15"><br/>
书号:<input type="text" datasrc="#XMLdata" datafld="ISBN" size="25"><br/>
作者:<input type="text" datasrc="#XMLdata" datafld="author" size="25"><br/>
出版社:<input type="text" datasrc="#XMLdata" datafld="publisher" size="23"><br/>
定价:<input type="text" datasrc="#XMLdata" datafld="price" size="15"><br/>
剩余数量:<input type="text" datasrc="#XMLdata" datafld="remain" size="15"><br/>
<hr/>
<input id="first" type="button" value="<<第一条" onclick="XMLdata.recordset.moveFirst">           <!--数据岛的基本方法-->
<input id="prev" type="button" value="<上一条" onclick="XMLdata.recordset.movePrevious">
<input id="next" type="button" value="下一条>" onclick="XMLdata.recordset.moveNext">
<input id="last" type="button" value="最后一条>>" onclick="XMLdata.recordset.moveLast">
<input id="add" type="button" value="添加" onclick="XMLdata.recordset.addNew"

</body>
</html>

第三步,测试,运行,看看效果,还是在tomcat容器中部署。

 

 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
XML:快速表列资料-资料系结|http://www.itonline.gd.cn
Python3实现超简易图书管理系统源码(控制台版)
在C#.net中怎么操作XML
实现 Castor 数据绑定,第 2 部分: 编组和解组 XML
WEB2.0学院
Download [PDF] An Introduction To Computational Learning Theory Mit Press Free – Usakochan PDF
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服