<script type="text/JavaScript"> alimama_pid="mm_10029469_121618_2136337"; alimama_titlecolor="000000"; alimama_descolor ="6A6A6A"; alimama_bgcolor="FFFFFF"; alimama_bordercolor="E1E1E1"; alimama_linkcolor="373737"; alimama_bottomcolor="FFFFFF"; alimama_anglesize="8"; alimama_bgpic="1"; alimama_icon="2"; alimama_sizecode="11"; alimama_width=760; alimama_height=90; alimama_type=2; </script><script src="http://a.alimama.cn/inf.js" type=text/javascript> </script>
使用IE5.0或者更高的版本,XML数据可以以数据岛的形式嵌入HTML页面。
在HTML页面中嵌入XML数据
使用非官方标准的<xml>标记可以将XML数据嵌入到HTML页面中。
XML数据可以象下面的例子那样嵌入HTML页面:
<xml id="note">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
</xml> |
或者象下面这样嵌入外部单独的XML文件:
<xml id="note" src="note.xml">
</xml> |
注意那个<xml>标记是一个HTML元素,而不是一个XML元素。
数据绑定
XML数据岛可以绑定到HTML元素上(比如表格)。
在下面的例子中,一个XML数据岛(ID=cdcat)被从外部XML文档载入。一个HTML的表格绑定到此数据岛上。HTML表格内部的span元素使用datafld属性和XML文档相应的XML元素相互绑定。
<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> |
如果你使用的是IE 5.0 或者更高版本, 你可以自己尝试一下try it yourself.
<html><br>
<body><br>
<xml id="cdcat" src="cd_catalog.xml" tppabs="http://www.w3schools.com/xml/cd_catalog.xml"></xml><br>
<table border="1" datasrc="#cdcat"><br>
<tr><br>
<td><span datafld="ARTIST"></span></td><br>
<td><span datafld="TITLE"></span></td><br>
</tr><br>
</table><br>
</body><br>
</html>
如果你使用的是IE 5.0 或者更高版本,你可以观看external XML file.
<?xml version="1.0" encoding="ISO-8859-1" ?>
- <!--
Edited with XML Spy v4.2
--> <script type="text/javascript">f(clean);</script>
<
TITLE
>
Empire Burlesque
</
TITLE
>
<
ARTIST
>
Bob Dylan
</
ARTIST
>
<
COUNTRY
>
USA
</
COUNTRY
>
<
COMPANY
>
Columbia
</
COMPANY
>
<
PRICE
>
10.90
</
PRICE
>
</
CD
>
<
TITLE
>
Hide your heart
</
TITLE
>
<
ARTIST
>
Bonnie Tyler
</
ARTIST
>
<
COUNTRY
>
UK
</
COUNTRY
>
<
COMPANY
>
CBS Records
</
COMPANY
>
<
PRICE
>
9.90
</
PRICE
>
</
CD
>
<
TITLE
>
Greatest Hits
</
TITLE
>
<
ARTIST
>
Dolly Parton
</
ARTIST
>
<
COUNTRY
>
USA
</
COUNTRY
>
<
COMPANY
>
RCA
</
COMPANY
>
<
PRICE
>
9.90
</
PRICE
>
</
CD
>
<
TITLE
>
Still got the blues
</
TITLE
>
<
ARTIST
>
Gary Moore
</
ARTIST
>
<
COUNTRY
>
UK
</
COUNTRY
>
<
COMPANY
>
Virgin records
</
COMPANY
>
<
PRICE
>
10.20
</
PRICE
>
</
CD
>
<
TITLE
>
Eros
</
TITLE
>
<
ARTIST
>
Eros Ramazzotti
</
ARTIST
>
<
COUNTRY
>
EU
</
COUNTRY
>
<
COMPANY
>
BMG
</
COMPANY
>
<
PRICE
>
9.90
</
PRICE
>
</
CD
>
<
TITLE
>
One night only
</
TITLE
>
<
ARTIST
>
Bee Gees
</
ARTIST
>
<
COUNTRY
>
UK
</
COUNTRY
>
<
COMPANY
>
Polydor
</
COMPANY
>
<
PRICE
>
10.90
</
PRICE
>
</
CD
>
<
TITLE
>
Sylvias Mother
</
TITLE
>
<
ARTIST
>
Dr.Hook
</
ARTIST
>
<
COUNTRY
>
UK
</
COUNTRY
>
<
COMPANY
>
CBS
</
COMPANY
>
<
PRICE
>
8.10
</
PRICE
>
</
CD
>
<
TITLE
>
Maggie May
</
TITLE
>
<
ARTIST
>
Rod Stewart
</
ARTIST
>
<
COUNTRY
>
UK
</
COUNTRY
>
<
COMPANY
>
Pickwick
</
COMPANY
>
<
PRICE
>
8.50
</
PRICE
>
</
CD
>
<
TITLE
>
Romanza
</
TITLE
>
<
ARTIST
>
Andrea Bocelli
</
ARTIST
>
<
COUNTRY
>
EU
</
COUNTRY
>
<
COMPANY
>
Polydor
</
COMPANY
>
<
PRICE
>
10.80
</
PRICE
>
</
CD
>
<
TITLE
>
When a man loves a woman
</
TITLE
>
<
ARTIST
>
Percy Sledge
</
ARTIST
>
<
COUNTRY
>
USA
</
COUNTRY
>
<
COMPANY
>
Atlantic
</
COMPANY
>
<
PRICE
>
8.70
</
PRICE
>
</
CD
>
<
TITLE
>
Black angel
</
TITLE
>
<
ARTIST
>
Savage Rose
</
ARTIST
>
<
COUNTRY
>
EU
</
COUNTRY
>
<
COMPANY
>
Mega
</
COMPANY
>
<
PRICE
>
10.90
</
PRICE
>
</
CD
>
<
TITLE
>
1999 Grammy Nominees
</
TITLE
>
<
ARTIST
>
Many
</
ARTIST
>
<
COUNTRY
>
USA
</
COUNTRY
>
<
COMPANY
>
Grammy
</
COMPANY
>
<
PRICE
>
10.20
</
PRICE
>
</
CD
>
<
TITLE
>
For the good times
</
TITLE
>
<
ARTIST
>
Kenny Rogers
</
ARTIST
>
<
COUNTRY
>
UK
</
COUNTRY
>
<
COMPANY
>
Mucik Master
</
COMPANY
>
<
PRICE
>
8.70
</
PRICE
>
</
CD
>
<
TITLE
>
Big Willie style
</
TITLE
>
<
ARTIST
>
Will Smith
</
ARTIST
>
<
COUNTRY
>
USA
</
COUNTRY
>
<
COMPANY
>
Columbia
</
COMPANY
>
<
PRICE
>
9.90
</
PRICE
>
</
CD
>
<
TITLE
>
Tupelo Honey
</
TITLE
>
<
ARTIST
>
Van Morrison
</
ARTIST
>
<
COUNTRY
>
UK
</
COUNTRY
>
<
COMPANY
>
Polydor
</
COMPANY
>
<
PRICE
>
8.20
</
PRICE
>
</
CD
>
<
TITLE
>
Soulsville
</
TITLE
>
<
ARTIST
>
Jorn Hoel
</
ARTIST
>
<
COUNTRY
>
Norway
</
COUNTRY
>
<
COMPANY
>
WEA
</
COMPANY
>
<
PRICE
>
7.90
</
PRICE
>
</
CD
>
<
TITLE
>
The very best of
</
TITLE
>
<
ARTIST
>
Cat Stevens
</
ARTIST
>
<
COUNTRY
>
UK
</
COUNTRY
>
<
COMPANY
>
Island
</
COMPANY
>
<
PRICE
>
8.90
</
PRICE
>
</
CD
>
<
TITLE
>
Stop
</
TITLE
>
<
ARTIST
>
Sam Brown
</
ARTIST
>
<
COUNTRY
>
UK
</
COUNTRY
>
<
COMPANY
>
A and M
</
COMPANY
>
<
PRICE
>
8.90
</
PRICE
>
</
CD
>
<
TITLE
>
Bridge of Spies
</
TITLE
>
<
ARTIST
>
T'Pau
</
ARTIST
>
<
COUNTRY
>
UK
</
COUNTRY
>
<
COMPANY
>
Siren
</
COMPANY
>
<
PRICE
>
7.90
</
PRICE
>
</
CD
>
<
TITLE
>
Private Dancer
</
TITLE
>
<
ARTIST
>
Tina Turner
</
ARTIST
>
<
COUNTRY
>
UK
</
COUNTRY
>
<
COMPANY
>
Capitol
</
COMPANY
>
<
PRICE
>
8.90
</
PRICE
>
</
CD
>
<
TITLE
>
Midt om natten
</
TITLE
>
<
ARTIST
>
Kim Larsen
</
ARTIST
>
<
COUNTRY
>
EU
</
COUNTRY
>
<
COMPANY
>
Medley
</
COMPANY
>
<
PRICE
>
7.80
</
PRICE
>
</
CD
>
<
TITLE
>
Pavarotti Gala Concert
</
TITLE
>
<
ARTIST
>
Luciano Pavarotti
</
ARTIST
>
<
COUNTRY
>
UK
</
COUNTRY
>
<
COMPANY
>
DECCA
</
COMPANY
>
<
PRICE
>
9.90
</
PRICE
>
</
CD
>
<
TITLE
>
The dock of the bay
</
TITLE
>
<
ARTIST
>
Otis Redding
</
ARTIST
>
<
COUNTRY
>
USA
</
COUNTRY
>
<
COMPANY
>
Atlantic
</
COMPANY
>
<
PRICE
>
7.90
</
PRICE
>
</
CD
>
<
TITLE
>
Picture book
</
TITLE
>
<
ARTIST
>
Simply Red
</
ARTIST
>
<
COUNTRY
>
EU
</
COUNTRY
>
<
COMPANY
>
Elektra
</
COMPANY
>
<
PRICE
>
7.20
</
PRICE
>
</
CD
>
<
ARTIST
>
The Communards
</
ARTIST
>
<
COUNTRY
>
UK
</
COUNTRY
>
<
COMPANY
>
London
</
COMPANY
>
<
PRICE
>
7.80
</
PRICE
>
</
CD
>
<
TITLE
>
Unchain my heart
</
TITLE
>
<
ARTIST
>
Joe Cocker
</
ARTIST
>
<
COUNTRY
>
USA
</
COUNTRY
>
<
COMPANY
>
EMI
</
COMPANY
>
<
PRICE
>
8.20
</
PRICE
>
</
CD
>
</
CATALOG
>
同样也可以实验this example
<html>
<body>
<xml id="cdcat" src="cd_catalog.xml" tppabs="http://www.w3schools.com/xml/cd_catalog.xml"></xml>
<table border="1" datasrc="#cdcat">
<thead>
<tr><th>Artist</th><th>Title</th></tr>
</thead>
<tfoot>
<tr><th colspan="2">This is my CD collection</th></tr>
</tfoot>
<tbody>
<tr>
<td><span datafld="artist"></span></td>
<td><span datafld="title"></span></td>
</tr>
</tbody>
</table>
</body>
</html>
论证元素<thead>, <tbody>, and <tfoot>.