新闻上一页,下一页用xml实现
这章讲了写XML应用程序的一个小框架。
Note: This example uses a Data Island, which only works in Internet Explorer.
注意:这个例子用到了数据岛,这只有在IE中才能使用。
The XML Example Document
XML样本文件
Look at the following XML document ("cd_catalog.xml"), that represents a CD catalog:
请看下面的XML文件("cd_catalog.xml"),它代表着一个CD名录:
<?xml version="1.0" encoding="ISO-8859-1"?> |
View the full "cd_catalog.xml" file in your browser.
在浏览器里查看完整的"cd_catalog.xml"文件
Load the XML Document Into a Data Island
把XML文档载入数据岛
A Data Island can be used to access the XML file.
数据岛可用于访问XML文件。
To get your XML document "inside" an HTML page, add an XML Data Island to the HTML page:
要在HTML页面中得到XML文档,得在HTML页面中添加一个XML数据岛:
<xml src="cd_catalog.xml" id="xmldso" async="false"> |
With the example code above, the XML file "cd_catalog.xml" will be loaded into an "invisible" Data Island called "xmldso". The async="false" attribute is added to make sure that all the XML data is loaded before any other HTML processing takes place
有了上面例子中的代码,XML文件"cd_catalog.xml"会被载入一个“可见”的数据岛,数据岛叫做“xmldso”。The async="false"属性的设置是为了确保在HTML处理过程发生之前,所有的XML数据都被载入了。
Bind the Data Island to an HTML Table
把数据岛绑定到HTML表格
To make the XML data visible on the HTML page, you must "bind" the Data Island to an HTML element.
为了使XML数据在HTML页面上可见,你必须把数据岛绑定到HTML的元素里
To bind the XML data to an HTML table, add a datasrc attribute to the table element, and add datafld attributes to the span elements inside the table data:
为了把数据岛绑定到HTML表格,给表格元素添加datasrc属性,并给表格数据的span 元素添加datafld属性
<table datasrc="#xmldso" width="100%" border="1"> <thead> <tr align="left"> </table> |
If you have IE 5.0 or higher: See how the XML data is displayed inside an HTML table.
如你有IE5以上版本的浏览器: 看看XML数据是如何在HTML表格中显示的.
Bind the Data Island to <span> or <div> Elements
把数据岛植入<span>或<div>元素
<span> or <div> elements can be used to display XML data.
<span>或<div>元素可用于显示XML数据
You don't have to use the HTML table element to display XML data. Data from a Data Island can be displayed anywhere on an HTML page.
你不必非得用HTML表格元素来显示XML数据。来自数据岛的数据可以在HTML页面的任何地方显示。
All you have to do is to add some <span> or <div> elements to your page. Use the datasrc attribute to bind the elements to the Data Island, and the datafld attribute to bind each element to an XML element, like this:
你所须做的只是给你的页面添加一些<span>或<div>元素。用datasrc属性把元素绑定数据岛,用datafld属性把每个元素绑定到一个XML元素上,就像这样:
<br />Title: |
or like this:
或像这样:
<br />Title: |
If you have IE 5.0 or higher: See how the XML data is displayed inside the HTML elements.
如你有IE5以上版本的浏览器: 可以看下XML数据是怎样在HTML元素里显示的.
Note that if you use an HTML <div> element, the data will be displayed on a new line.
注意如果你用了HTML元素<div>,数据将会在新的一行显示
With the examples above, you will only see one line of your XML data. To navigate to the next line of data, you have to add some scripting to your code.
上面的例子里,你将看到的只是你的XML数据中的一行,为了操控下行数据,你得给你的代码添加点脚本。
Add a Navigation Script
添加一个导航脚本程序
Navigation has to be performed by a script
通过脚本程序可以实现数据的导航过程
To add navigation to the XML Data Island, create a script that calls the movenext() and moveprevious() methods of the Data Island.
为了给数据岛添加导航,创立一个脚本,名为数据岛的“下一步”movenext()和“上一步“moveprevious()方法。
<script type="text/javascript"> |
If you have IE 5.0 or higher: See how you can navigate through the XML records
如你有IE5以上的浏览器: 看下XML记录是怎样进行导航的.