这里是示例代码:
<HTML XMLNS:MSIE>
<HEAD>
<meta name=vs_targetSchema content="HTML 4.0">
<META NAME="GENERATOR" Content="Microsoft Visual Studio 7.0">
<TITLE>结构化存储示例</TITLE>
<style>
@media all {
MSIE/:localtable {behavior:url(#default#userData);}
}
</style>
<script language=javascript>
<!--
function addBook(sTitle,sAuthor){
var dso = SimpleData.recordset;
dso.addNew();
dso.fields("Title") = sTitle;
dso.fields("Author") = sAuthor;
dso.update();
}
function saveToLocal(){
localtable.setAttribute("records",SimpleData.xml);
localtable.save("localtable");
}
function loadFromLocal(){
localtable.load("localtable");
SimpleData.XMLDocument.loadXML(localtable.getAttribute("records"));
}
//-->
</script>
</HEAD>
<BODY>
<MSIE:localtable id=localtable></MSIE:localtable>
<xml id=SimpleData>
<root>
<book>
<Title>我的童年</Title>
<Author>高尔基</Author>
</book>
<book>
<Title>在人间</Title>
<Author>高尔基</Author>
</book>
<book>
<Title>我的大学</Title>
<Author>高尔基</Author>
</book>
</root>
</xml>
增加书籍<br>
名称:<input id=Title><br>
作者:<input id=Author><br>
<input type=button id=add value="添加书籍" onclick="addBook(Title.value,Author.value);">
<hr size=1>
<input type=button value="保存数据到本地" onclick="saveToLocal()">
<input type=button value="从本地读取数据" onclick="loadFromLocal()">
<hr size=1>
<table datasrc=#SimpleData width=400>
<thead bgcolor="Lavender">
<tr>
<td width=50%>名称</td>
<td width=50%>作者</td>
</tr>
</thead>
<tbody bgcolor="WhiteSmoke">
<tr>
<td><span datafld=Title></span></td>
<td><span datafld=Author></span></td>
</tr>
</tbody>
</table>
<hr size=1>
<span style="font-size:9pt">Copyright 2001 Think Space Soft.<br>
Author: <b>JoJo</b><br>
Date: <b>2001.5.30</b></span>
</BODY>
</HTML>