XML数据岛
使用XML数据岛可以快速操作XML~下面我下个简单的示例。
示例1:html里直接使用数据岛连接XML文件
<html>
<head>
<title>table.html</title>
<xml id="users" src="users.xml"></xml> <!--导入数据-->
</head>
<body>
<center>
<table datasrc="#users" id="user" border="1px"> <!--使用数据岛-->
<thead>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
</thead>
<tr>
<td><div datafld="name"></div></td>
<td><div datafld="age"></div></td>
<td><div datafld="sex"></div></td>
</tr>
</table>
</center>
</body>
</html>
示例二:通过JavaScript控制XML数据`
<html>
<head>
<title>users.html</title>
<xml id="users" src="users.xml"></xml>
<script type="text/javascript" language="javascript">
function firstrec(){
users.recordset.moveFirst()
}
function lastrec(){
users.recordset.moveLast()
}
function previousrec(){
if(!users.recordset.BOF){
users.recordset.movePrevious()
if(users.recordset.BOF){
users.recordset.moveFirst()
}
}
}
function nextrec(){
if(!users.recordset.EOF){
users.recordset.moveNext()
if(users.recordset.EOF){
users.recordset.moveLast()
}
}
}
</script>
</head>
<body>
<center>
<table align="center">
<tr>
<td>姓名</td>
<td><input type="text" datasrc="#users" datafld="name"/></td>
</tr>
<tr>
<td>年龄</td>
<td><input type="text" datasrc="#users" datafld="age"/></td>
</tr>
<tr>
<td>性别</td>
<td><input type="text" datasrc="#users" datafld="sex"/></td>
</tr>
<tr>
<td colspan="2" align="center">
<button onclick="firstrec()"><<</button>
<button onclick="previousrec()"><</button>
<button onclick="nextrec()">></button>
<button onclick="lastrec()">>></button>
</td>
</tr>
</table>
</center>
</body>
</html>
示例1:html里直接使用数据岛连接XML文件
<html>
<head>
<title>table.html</title>
<xml id="users" src="users.xml"></xml> <!--导入数据-->
</head>
<body>
<center>
<table datasrc="#users" id="user" border="1px"> <!--使用数据岛-->
<thead>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
</thead>
<tr>
<td><div datafld="name"></div></td>
<td><div datafld="age"></div></td>
<td><div datafld="sex"></div></td>
</tr>
</table>
</center>
</body>
</html>
示例二:通过JavaScript控制XML数据`
<html>
<head>
<title>users.html</title>
<xml id="users" src="users.xml"></xml>
<script type="text/javascript" language="javascript">
function firstrec(){
users.recordset.moveFirst()
}
function lastrec(){
users.recordset.moveLast()
}
function previousrec(){
if(!users.recordset.BOF){
users.recordset.movePrevious()
if(users.recordset.BOF){
users.recordset.moveFirst()
}
}
}
function nextrec(){
if(!users.recordset.EOF){
users.recordset.moveNext()
if(users.recordset.EOF){
users.recordset.moveLast()
}
}
}
</script>
</head>
<body>
<center>
<table align="center">
<tr>
<td>姓名</td>
<td><input type="text" datasrc="#users" datafld="name"/></td>
</tr>
<tr>
<td>年龄</td>
<td><input type="text" datasrc="#users" datafld="age"/></td>
</tr>
<tr>
<td>性别</td>
<td><input type="text" datasrc="#users" datafld="sex"/></td>
</tr>
<tr>
<td colspan="2" align="center">
<button onclick="firstrec()"><<</button>
<button onclick="previousrec()"><</button>
<button onclick="nextrec()">></button>
<button onclick="lastrec()">>></button>
</td>
</tr>
</table>
</center>
</body>
</html>