生成XML文件

<%
set conn=server.createobject("adodb.connection")
conn.open "provider=microsoft.jet.oledb.4.0;data source="&server.mappath("db1.mdb")
%>

<%
  XmlFileName="1_all.xml"
  LineHead="<?xml version=""1.0"" encoding=""gb2312""?>" & vbcrlf
  LineHead=LineHead & "<channel>" & vbcrlf
  LineHead=LineHead & "<createTime>" & Now() & "</createTime>" & vbcrlf
  LineHead=LineHead & "<title>博客</title>" & vbcrlf
  LineHead=LineHead & "<link>http://www.siyuroom.com</link>" & vbcrlf
  LineHead=LineHead & "<category>论坛BBS</category>" & vbcrlf
  LineHead=LineHead & "<copyright>网站</copyright>" & vbcrlf
  LineHead=LineHead & "<webMaster>test115@163.com</webMaster>" & vbcrlf
   
  Dim LineItem(10)
  Dim LineID(10)
  Dim LineTitle(10)
  Dim LineLink(10)
  Dim LineAuthor(10)
  Dim LinePubDate(10)
  Dim LineDescription(10)
  Dim LineReplyNum(10)
  Dim LineClickNum(10)
  Dim LineAuthorID(10)
  Dim LineEndItem(10)
  
  Dim iLine
  iLine=1
  strSql2="select *from forum"
  Set rs2=conn.execute(strSql2)
  
  Do Until rs2.eof
  
   LineItem(iLine)          ="<item>"
   LineID(iLine)            ="<ID>" & rs2("id") & "</ID>"
   LineTitle(iLine)         ="<title><![CDATA[" & rs2("topic") & "]]></title>"
   LineLink(iLine)          ="<link>http://www.siyuroom.com/forum/ShowPost.asp?id=" & rs2("id") & "</link>"
   LineAuthor(iLine)        ="<author><![CDATA[" & rs2("userhome") & "]]></author>"
   LinePubDate(iLine)   ="<pubDate>" & rs2("posttime") & "</pubDate>"
   LineDescription(iLine)   ="<description><![CDATA[" & rs2("topic") & "]]></description>"
   LineReplyNum(iLine)      ="<replyNum>" & rs2("replies") & "</replyNum>"
   LineClickNum(iLine)      ="<clickNum>" & rs2("views") & "</clickNum>"
   LineAuthorID(iLine)      ="<authorID>" & rs2("uid") & "</authorID>"
   LineEndItem(iLine)       ="</item>"

   iLine=iLine+1
   rs2.movenext
  Loop
  
  
  LineBottom="</channel>" & vbcrlf
  
  FilePath=Server.MapPath(XmlFileName)
  Set fso=Server.CreateObject("Scripting.FileSystemObject")
  Set fout=fso.CreateTextFile(FilePath)
  fout.WriteLine LineHead
  
  For i=1 To iLine-1
   fout.WriteLine LineItem(i)
   fout.WriteLine LineID(i)
   fout.WriteLine LineTitle(i)
   fout.WriteLine LineLink(i)
   fout.WriteLine LineAuthor(i)
   fout.WriteLine LinePubDate(i)
   fout.WriteLine LineDescription(i)
   fout.WriteLine LineReplyNum(i)
   fout.WriteLine LineClickNum(i)
   fout.WriteLine LineAuthorID(i)
   fout.WriteLine LineEndItem(i)
  Next
  
  fout.WriteLine LineBottom

  response.write "已成功生成文档 <a href='" & XmlFileName & "' target=_blank>" & XmlFileName & "</a><br>"
%>

    A+
发布日期:2007年03月06日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: