ASP生成XML文件
来源:风之相随blog 时间:2009-06-29 16:28:00
今天一个项目上需要,修改了一些属性,测试成功。
<!--#include file="conn.asp"-->
<%'从数据库中读数据
dim i
dim TopicID(7),BoardID(7),Caption(7),LastTime(7)
'-------------------读数据
set rs = Server.CreateObject("Adodb.recordset")
sql = "Select * from new order by new_id desc"
rs.open sql,conn,1,1
i=1
do while not rs.eof
TopicID(i)=rs("New_ID")
BoardID(i)=rs("new_topic")
Caption(i)=rs("new_stype")
LastTime(i)=rs("new_date")
rs.movenext
i=i+1
if i > 7 then exit do
loop
'------------------生成xml
Set f = Server.CreateObject("Scripting.FileSystemObject")
'Set myfile = f.Createtextfile(server.mappath(file),true)
files = "output.xml" '文件输出路径
Set myfile = f.Createtextfile(server.mappath(files),true)
myfile.writeline "<?xml version=""1.0"" encoding=""gb2312""?>"
myfile.writeline "<data>"
for i=1 to 7
myfile.writeline "<gong>"
myfile.writeline "<TopicID>"&TopicID(i)&"</TopicID>"
myfile.writeline "<BoardID>"&BoardID(i)&"</BoardID>"
myfile.writeline "<Caption>"&Caption(i)&"</Caption>"
myfile.writeline "<LastTime>"&LastTime(i)&"</LastTime>"
myfile.writeline "</gong>"
next
myfile.writeline "</data>"
myfile.close
%>
项目中使用:
<!--#include file="conn.asp"-->
<%'从数据库中读数据
dim i
dim New_ID(10),New_topic(10),New_stype(10),New_pic(10)
'-------------------读数据
set rs = Server.CreateObject("Adodb.recordset")
sql = "Select * from new order by new_id desc"
rs.open sql,conn,1,1
i=1
do while not rs.eof
New_ID(i)=rs("New_ID")
New_topic(i)=rs("new_topic")
New_stype(i)=rs("new_stype")
New_pic(i)=rs("new_pic")
rs.movenext
i=i+1
if i > 10 then exit do
loop
'------------------生成xml
Set f = Server.CreateObject("Scripting.FileSystemObject")
'Set myfile = f.Createtextfile(server.mappath(file),true)
files = "swf/imgList.xml" '文件输出路径
Set myfile = f.Createtextfile(server.mappath(files),true)
myfile.writeline "<?xml version=""1.0"" encoding=""gb2312""?>"
myfile.writeline "<imgList>"
myfile.writeline "<pic>"
for i=1 to 10
myfile.writeline "<list path='uploadfile/"&New_pic(i)&"' smallpath='uploadfile/"&New_pic(i)&"' smallinfo='"&New_stype(i)&"' news.asp?bigCate=今创工程&smallCate="&New_stype(i)&" /list>"
next
myfile.writeline "</pic>"
myfile.writeline "<rollTime fade_in=""10"">4</rollTime>"
myfile.writeline "<text font=""黑体"" size=""12"" bold=""true"" color=""0xfffffff""></text>"
myfile.writeline "</imgList>"
myfile.close
%>