在HTML中,可以通过<xml>标记嵌入XML文档或引用一个外部XML文档,这部分嵌入HTML页面中的XML数据称为XML数据岛。
XML数据岛的使用仅限于IE浏览器。
创建XML对象后,可以与HTML文档中的table、span、div等元素绑定,绑定元素的datasrc属性为XML元素的id属性,前面要加上“#”;datafld属性为要显示的字段内容。
booklist.xml
booklist.html
运行结果:
XML数据岛的使用仅限于IE浏览器。
创建XML对象后,可以与HTML文档中的table、span、div等元素绑定,绑定元素的datasrc属性为XML元素的id属性,前面要加上“#”;datafld属性为要显示的字段内容。
booklist.xml
<?
xml version="1.0" encoding="UTF-8"
?>
< booklist >
< book >
< name > Ajax </ name >
< price > $5.95 </ price >
< description > Foundations of Ajax. </ description >
</ book >
< book >
< name > Ajax Patterns </ name >
< price > $7.95 </ price >
< description > Introduction of Ajax Patterns. </ description >
</ book >
< book >
< name > Ajax Web App </ name >
< price > $8.95 </ price >
< description > Edition 2. </ description >
</ book >
< book >
< name > Core CSS </ name >
< price > $4.50 </ price >
< description > A book for CSS. </ description >
</ book >
< book >
< name > JSF and Ajax </ name >
< price > $6.95 </ price >
< description > Apress. </ description >
</ book >
</ booklist >
< booklist >
< book >
< name > Ajax </ name >
< price > $5.95 </ price >
< description > Foundations of Ajax. </ description >
</ book >
< book >
< name > Ajax Patterns </ name >
< price > $7.95 </ price >
< description > Introduction of Ajax Patterns. </ description >
</ book >
< book >
< name > Ajax Web App </ name >
< price > $8.95 </ price >
< description > Edition 2. </ description >
</ book >
< book >
< name > Core CSS </ name >
< price > $4.50 </ price >
< description > A book for CSS. </ description >
</ book >
< book >
< name > JSF and Ajax </ name >
< price > $6.95 </ price >
< description > Apress. </ description >
</ book >
</ booklist >
<
html
>
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=UTF-8" >
< title > XML数据岛 </ title >
</ head >
< body >
XML data begin: < br >
< xml id ="MyBookList" src ="booklist.xml" ></ xml >
< table datasrc ="#MyBookList" border ="1" >
< thead >
< th > name </ th >
< th > price </ th >
< th > description </ th >
</ thead >
< tr align ="left" >
< td >< span datafld ="name" ></ span ></ td >
< td >< span datafld ="price" ></ span ></ td >
< td >< span datafld ="description" ></ span ></ td >
</ tr >
</ table >
</ body >
</ html >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=UTF-8" >
< title > XML数据岛 </ title >
</ head >
< body >
XML data begin: < br >
< xml id ="MyBookList" src ="booklist.xml" ></ xml >
< table datasrc ="#MyBookList" border ="1" >
< thead >
< th > name </ th >
< th > price </ th >
< th > description </ th >
</ thead >
< tr align ="left" >
< td >< span datafld ="name" ></ span ></ td >
< td >< span datafld ="price" ></ span ></ td >
< td >< span datafld ="description" ></ span ></ td >
</ tr >
</ table >
</ body >
</ html >