<html>
<title>www.ttasp.net(Create XML from Access)</title>
<body bgcolor="#FFFFFF">
<%
'被查询的数据库名称
accessdb="state_info"
'连接字符串到数据库
cn="DRIVER={Microsoft Access Driver (*.mdb)};"
cn=cn & "DBQ=" & server.mappath(accessdb)
'创建一个服务器记录设置对象
Set rs = Server.CreateObject("ADODB.Recordset")
'查询来自州的信息数据库的州的表格
sql = "select state,statename,capital,year,order from states order by states.order "
'执行sql
rs.Open sql, cn
'移动第一个记录
rs.MoveFirst
'输出文档名称
file_being_created= "states.xml"
'创建一个文件系统对象
set fso = createobject("scripting.filesystemobject")
‘创建文本文件——正确或者覆盖任何之前的文件
‘写出数据库输出到相同目录的xml文件
Set act = fso.CreateTextFile(server.mappath(file_being_created), true)
'所有顶端的非重复xml
act.WriteLine("<?xml version=""1.0""?>")
act.WriteLine("<states>")
'循环输出所有的查询结果到xml文件
do while not rs.eof
'计算给出每个记录一个连续的列表
counter=counter+1
act.WriteLine("<state id="""& counter &""">")
act.WriteLine("<state_abbrev>" & rs("state") & "</state_abbrev>" )
act.WriteLine("<state_name>" & rs("statename") & "</state_name>" )
act.WriteLine("<state_capital>" & rs("capital") & "</state_capital>")
act.WriteLine("<year_admitted>"& rs("year") & "</year_admitted>")
act.WriteLine("<order_admitted>"& rs("order") & "</order_admitted>")
act.WriteLine("</state>")
'移动到下个记录
rs.movenext
loop
'所有在顶部的非重复xml
act.WriteLine("</states>")
'关闭对象(xml)
act.close
'写出新创建的浏览器xml文件链接
response.write "<a href='states.xml'>States</a> (.xml) has been created <br>"
response.write "on " & now() & "<br>"
%>
</body>
</html>
热门信息
阅读 (109)
1 什么样的编程语言是最值得我们学习的呢?阅读 (109)
2 asp 如何解析api接口返回的xml阅读 (109)
3 ASP-数组阅读 (108)
4 asp网站伪静态化URL Rewrite中的httpd.ini伪静态化规则编写方法阅读 (105)
5 asp取access数据库里本周、本月、本季度的记录~