当前位置: 首页 > 网络学院 > XML相关教程 > XML > XML 数据岛

XML
XML DHTML行为
XML 相关技术
XML 编辑器
XML 摘要
XML 实例
XML字符编码
xml 文档树
IE和火狐读取XML方法比较

XML 数据岛


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 795 ::
收藏到网摘: n/a

With Internet Explorer, the unofficial <xml> tag can be used to create an XML data island.
通过IE浏览器,非正式的<xml>标记可用于创建一个XML数据岛。


XML Data Embedded in HTML
嵌入HTML的XML数据

An XML data island is XML data embedded into an HTML page.
XML数据岛是嵌入HTML页面的XML数据。

Here is how it works; assume we have the following XML document ("note.xml"):
接下来讲讲它的工作原理。假设我们有下面这份XML文档("note.xml"):

<?xml version="1.0" encoding="ISO-8859-1"?>

<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>

<body>Don't forget me this weekend!</body>
</note>

Then, in an HTML document, you can embed the XML file above with the <xml> tag. The id attribute of the <xml> tag defines an ID for the data island, and the src attribute points to the XML file to embed:
接着,在一份HTML文档里,你可以嵌入一份XML文档。XML文档最顶端包含<xml>标签。<xml>标签的ID属性定义了数据岛的ID,src属性指明了嵌入的XML文件路径:

<html>
<body>
<xml id="note" src="note.xml"></xml>
</body>
</html>

However, the embedded XML data is, up to this point, not visible for the user.
然而,嵌入的XML数据对使用者来讲是不可见的。

The next step is to format and display the data in the data island by binding it to HTML elements.
下一步就是通过把数据岛的数据绑定到HTML元素中来格式化数据以及显示数据。


Bind Data Island to HTML Elements
把数据岛绑定到HTML元素

In the next example, we will embed an XML file called "cd_catalog.xml" into an HTML file.
在下面这个案例中,我们把一份名为 "cd_catalog.xml" XML文件嵌套到HTML文件中:

查看"cd_catalog.xml".

The HTML file looks like this:
这份HTML文件是这样的:

<html>

<body>

<xml id="cdcat" src="cd_catalog.xml"></xml>

<table border="1" datasrc="#cdcat">

<tr>
<td><span datafld="ARTIST"></span></td>
<td><span datafld="TITLE"></span></td>
</tr>
</table>

</body>
</html>

Example explained:
案例说明:

The datasrc attribute of the <table> tag binds the HTML table element to the XML data island. The datasrc attribute refers to the id attribute of the data island.
<table>标签中的 “datasrc” 属性把HTML 表格(table)元素绑定到XML数据岛。Datasrc属性指的是数据岛的ID属性:

<td> tags cannot be bound to data, so we are using <span> tags. The <span> tag allows the datafld attribute to refer to the XML element to be displayed. In this case, it is datafld="ARTIST" for the <ARTIST> element and datafld="TITLE" for the <TITLE> element in the XML file. As the XML is read, additional rows are created for each <CD> element.
<td>标签不能被绑定到数据上,所以我们用<span>标签。<span>标签允许datafld属性指定要被显示的XML元素。在这种情况下,XML文件中的 datafld="ARTIST" 代表了<ARTIST>元素,datafld="TITLE" 代表了<TITLE>元素。当读取XML时,每个<CD>元素都会重新换行。

If you are running IE 5.0 or higher, you can try it yourself.
如果你使用IE 5.0或更高版本的浏览器, 那么就自己动手试一下吧

Also try this example, demonstrating <thead>, <tbody>, and <tfoot>.
也可以试下 这个案例, 验证<thead>、<tbody> 和 <tfoot>。

评论 (0) All

登陆 | 还没注册?