惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
C
CXSECURITY Database RSS Feed - CXSecurity.com
V
Visual Studio Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
小众软件
小众软件
L
LangChain Blog
Cyberwarzone
Cyberwarzone
美团技术团队
The Register - Security
The Register - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tor Project blog
V
V2EX
Security Archives - TechRepublic
Security Archives - TechRepublic
Hacker News: Ask HN
Hacker News: Ask HN
L
LINUX DO - 最新话题
Recent Announcements
Recent Announcements
H
Hackread – Cybersecurity News, Data Breaches, AI and More
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
aimingoo的专栏
aimingoo的专栏
人人都是产品经理
人人都是产品经理
F
Full Disclosure
V2EX - 技术
V2EX - 技术
The Cloudflare Blog
博客园 - 叶小钗
T
Threat Research - Cisco Blogs
阮一峰的网络日志
阮一峰的网络日志
G
GRAHAM CLULEY
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Latest news
Latest news
S
Security @ Cisco Blogs
Spread Privacy
Spread Privacy
Project Zero
Project Zero
K
Kaspersky official blog
MyScale Blog
MyScale Blog
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
博客园 - 【当耐特】
Hacker News - Newest:
Hacker News - Newest: "LLM"
大猫的无限游戏
大猫的无限游戏
P
Privacy International News Feed
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
C
Cybersecurity and Infrastructure Security Agency CISA
Webroot Blog
Webroot Blog
罗磊的独立博客
Vercel News
Vercel News
N
News and Events Feed by Topic
A
Arctic Wolf
C
CERT Recently Published Vulnerability Notes

博客园 - 陋室

成功与一截树枝 sql 操作全集-整理收藏 JavaScript使用技巧精萃(转载) ASP.NET 中在指定的位置处插入字符 提示按下大写键的控件:MQTool(提供下载) 如何在mail的正文显示图片 NET设计模式之一:装饰模式(Decorator Pattern) 微软AJAX 教学系列第一讲:ScriptManager控件 微软AJAX 教学系列第一讲:局部刷新Partial Page Updates(翻译) 李开复:21世纪最需要的7种人才 Building a File Service 超卓越的你_读完后让你恢复自信 how to write professional business letters? 到底什么是托管,什么是非托管的研究 数据库设计中的五个范式(本文转载,收藏下) ASP.NET程序的优化建议<转> ASP.NET部署与安装_MSI制作图文教程. 在打包的时候,创建应用程序池,并自动将程序assign到新创建的池中(MSI制作) Understand SQL Cache Notifications
如何直接用XML做数据源?
陋室 · 2008-04-24 · via 博客园 - 陋室

XML 文档实例

请看下面这个 XML 文档 ( "cd_catalog.xml" ),它描述了一个 CD 目录:

<?xml version="1.0" encoding="ISO-8859-1"?>
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
<! [CDATA[ more]]></CATALOG>

将 XML 文档载入数据岛

数据岛可用于访问 XML 文件。

如需在 HTML 页面“内部”获取 XML 文档,请您向 HTML 页面添加数据岛:

<xml src="cd_catalog.xml" id="xmldso" async="false"></xml>

通过使用上面例子中的代码,XML 文件 "cd_catalog.xml" 将被载入一个名为 "xmldso" 的“可见的”数据岛中。添加 async="false" 属性的目的是为了在其他的 HTML 处理开始进行之前所有的 XML 数据均被载入。

将数据岛绑定至 HTML 表格

如果要让 XML 数据在 HTML 页面上可见,您必须把数据岛绑定至某个 HTML 元素。

如需向某个 HTML 表格绑定XML数据,请向 table 元素添加 datasrc 属性,并向 table 元素内部的 span 元素添加 datafld 属性:

<table datasrc="#xmldso" width="100%" border="1">
<thead>
<th>Title</th>
<th>Artist</th>
<th>Year</th>
</thead>
<tr align="left">
<td><span datafld="TITLE"></span></td>
<td><span datafld="ARTIST"></span></td>
<td><span datafld="YEAR"></span></td> 


将数据岛绑定至 <span> 或 <div> 元素

<span> 或 <div> 元素可用于显示 XML 数据。

您不必使用 HTML 表格来显示 XML 数据。从数据岛那里来的数据可显示在 HTML 页面上的任何地方。

所有您需要做的事情就是向页面添加 <span> 或 <div> 元素。使用 datasrc 属性把元素绑定至数据岛,并使用 datafld 属性把每个元素绑定至 XML 元素,就像这样:

<br />Title:
<span datasrc="#xmldso" datafld="TITLE"></span>
<br />Artist:
<span datasrc="#xmldso" datafld="ARTIST"></span>
<br />Year:
<span datasrc="#xmldso" datafld="YEAR"></span>
或者像这样做:
<br />Title:
<div datasrc="#xmldso" datafld="TITLE"></div>
<br />Artist:
<div datasrc="#xmldso" datafld="ARTIST"></div>
<br />Year:
<div datasrc="#xmldso" datafld="YEAR"></div>
</tr>

添加导航脚本

导航功能可由脚本来实现。

为了向 XML 数据岛添加导航,你需要创建可调用数据岛的 movenext() 和 moveprevious() 方法的脚本。

<script type="text/javascript">
function movenext()
{
x
=xmldso.recordset
if (x.absoluteposition < x.recordcount)
{
x.movenext()
}

}

function moveprevious()
{
x
=xmldso.recordset
if (x.absoluteposition > 1)
{
x.moveprevious()
}

}

</script>

EXample: 

Code