asp生成xml文件代码

 代码如下 复制代码

<!--#include file="config.asp"-->
<%
Dim Rs,SQL,foundstr
Dim classid,ChildStr
Dim RssBody,RssTitle,RssHomePageUrl
Dim XMLDOM,node,Cnode,Cnode1,msginfo
Set XMLDOM = Server.CreateObject("Microsoft.FreeThreadedXMLDOM")
XMLDOM.appendChild(XMLDOM.createElement("rss"))
XMLDOM.documentElement.attributes.setNamedItem(XMLDOM.createNode(2,"version","")).text="2.0"
Set node = XMLDOM.documentElement.appendChild(XMLDOM.createNode(1,"channel",""))
RssHomePageUrl = Newasp.SiteUrl
RssTitle = "获取文章列表"
classid = Newasp.CheckNumeric(Request("classid"))

Dim ChannelRootDir
ChannelRootDir = Newasp.InstallDir & Newasp.ChannelDir

Sub XMLArticleList()
 Dim specialID,stype
 If Trim(Request("specialID")) <> "" Then
  specialID = Newasp.CheckNumeric(Request("SpecialID"))
  specialID = CLng(specialID)
  If specialID = 0 Then
   foundstr = "And A.specialID>0 ORDER BY A.WriteTime DESC ,A.ArticleID DESC"
  Else
   foundstr = "And A.specialID=" & specialID & " ORDER BY A.WriteTime DESC ,A.ArticleID DESC"
  End If
 Else
  If classid > 0 Then
   SQL = "SELECT ClassName,ChildStr FROM [NC_Classify] WHERE ChannelID = " & ChannelID & " And ClassID=" & CLng(classid)
   Set Rs = Newasp.Execute(SQL)
   If Rs.BOF And Rs.EOF Then
    Set Cnode=node.appendChild(XMLDOM.createNode(1,"item",""))
    Cnode.appendChild(XMLDOM.createNode(1,"title","")).text="没有找到文章分类"
    Cnode.appendChild(XMLDOM.createNode(1,"link","")).text=RssHomePageUrl
    Cnode.appendChild(XMLDOM.createNode(1,"author","")).text=Newasp.SiteName
    Cnode.appendChild(XMLDOM.createNode(1,"pubDate","")).text=Now()
    Set Cnode1=Cnode.appendChild(XMLDOM.createNode(1,"description",""))
    msginfo= "没有找到文章分类!"
    Cnode1.appendChild(XMLDOM.createCDATASection(msginfo))
    Rs.Close: Set Rs = Nothing
    Exit Sub
   Else
    RssTitle = Rs("ClassName")
    ChildStr = Rs("ChildStr")
   End If
   Rs.Close:Set Rs = Nothing
   foundstr = "And A.ClassID in (" & ChildStr & ") ORDER BY A.WriteTime DESC ,A.ArticleID DESC"
  Else
   RssTitle = "全部文章列表"
   foundstr = "ORDER BY A.WriteTime DESC ,A.ArticleID DESC"
  End If
 End If
 If Trim(Request("type")) <> "" Then
  stype = Newasp.CheckNumeric(Request("type"))
  stype = CInt(stype)
  If stype = 0 Then
   foundstr = Replace(foundstr, "A.WriteTime", "A.AllHits")
  Else
   foundstr = "And IsBest>0 " & foundstr
  End If
 End If
 node.appendChild(XMLDOM.createNode(1,"title","")).text=Newasp.SiteName&"--"&RssTitle
 node.appendChild(XMLDOM.createNode(1,"link","")).text=Newasp.SiteUrl
 node.appendChild(XMLDOM.createNode(1,"language","")).text="zh-cn"
 node.appendChild(XMLDOM.createNode(1,"description","")).text=Newasp.SiteName
 node.appendChild(XMLDOM.createNode(1,"copyright","")).text=Newasp.SiteUrl
 node.appendChild(XMLDOM.createNode(1,"generator","")).text="Rss Generator By Newasp.Net"

 Dim HtmlFileName,HtmlFileUrl
 SQL = " A.ArticleID,A.ClassID,A.title,A.Content,A.WriteTime,A.HtmlFileDate,A.author,"
 SQL = "SELECT TOP 100 " & SQL & " C.ClassName,C.HtmlFileDir,C.UseHtml,B.ChannelDir,B.StopChannel,B.ModuleName,B.IsCreateHtml,B.HtmlExtName,B.HtmlPath,B.HtmlForm,B.HtmlPrefix FROM ([NC_Article] A INNER JOIN [NC_Classify] C On A.ClassID=C.ClassID) INNER JOIN [NC_Channel] B On A.ChannelID=B.ChannelID WHERE A.isAccept>0 And A.ChannelID=" & CLng(ChannelID) & " " & foundstr & ""
 Set Rs = Newasp.Execute(SQL)
 If Rs.BOF And Rs.EOF Then
  Set Cnode=node.appendChild(XMLDOM.createNode(1,"item",""))
  Cnode.appendChild(XMLDOM.createNode(1,"title","")).text="没有找到文章"
  Cnode.appendChild(XMLDOM.createNode(1,"link","")).text=RssHomePageUrl
  Cnode.appendChild(XMLDOM.createNode(1,"author","")).text=Newasp.SiteName
  Cnode.appendChild(XMLDOM.createNode(1,"pubDate","")).text=Now()
  Set Cnode1=Cnode.appendChild(XMLDOM.createNode(1,"description",""))
  msginfo= "没有找到文章!"
  Cnode1.appendChild(XMLDOM.createCDATASection(msginfo))
  Rs.Close: Set Rs = Nothing
  Exit Sub
 Else
  Do While Not Rs.EOF
   HtmlFileName = Newasp.ReadFileName(Rs("HtmlFileDate"), Rs("ArticleID"), Rs("HtmlExtName"), Rs("HtmlPrefix"), Rs("HtmlForm"), "")
   If Rs("IsCreateHtml") <> 0 Then
    HtmlFileUrl = ShowChannelPath(ChannelRootDir,Rs("HtmlFileDir")) & Newasp.ShowDatePath(Rs("HtmlFileDate"), Rs("HtmlPath")) & HtmlFileName
   Else
    HtmlFileUrl = Newasp.GetChannelDir(ChannelID) & "show.asp?id=" & Rs("ArticleID")
   End If
   If LCase(Left(HtmlFileUrl,7)) <> "http://" Then HtmlFileUrl = RssHomePageUrl & HtmlFileUrl
   Set Cnode=node.appendChild(XMLDOM.createNode(1,"item",""))
   Cnode.appendChild(XMLDOM.createNode(1,"title","")).text=Replace(Rs("title"), "&nbsp;", " ")
   Cnode.appendChild(XMLDOM.createNode(1,"link","")).text=HtmlFileUrl
   Cnode.appendChild(XMLDOM.createNode(1,"category","")).text=Rs("ClassName")
   Cnode.appendChild(XMLDOM.createNode(1,"author","")).text=Rs("author")
   Cnode.appendChild(XMLDOM.createNode(1,"pubDate","")).text=Rs("WriteTime")
   Set Cnode1=Cnode.appendChild(XMLDOM.createNode(1,"description",""))
   msginfo=  Newasp.CutString(Rs("Content"), 300)
   Cnode1.appendChild(XMLDOM.createCDATASection(msginfo))
   Rs.MoveNext
  Loop
 End If
 Rs.Close: Set Rs = Nothing
End Sub

Sub ShowXML()
 Response.Clear
 Response.CharSet="gb2312"
 Response.ContentType="text/xml"
 Response.Write "<?xml version=""1.0"" encoding=""gb2312""?>"&vbNewLine
 Response.Write XMLDOM.xml
 Set XMLDOM=Nothing
End Sub

XMLArticleList()
ShowXML()
CloseConn
%>

时间: 2024-12-08 13:24:39

asp生成xml文件代码的相关文章

asp 生成feed文件代码

<% function AddSiteURL(ByVal Str)   If IsNull(Str) Then    AddSiteURL = ""    Exit Function   End If   Dim re   Set re=new RegExp   With re     .IgnoreCase =True     .Global=True         .Pattern="<img (.*?)src=""(?!(http|ht

asp生成静态文件代码

<% Dim Rs,SQL,HtmlContent Dim ChannelRootDir,strInstallDir,strIndexName Dim flashid,downid,showurl,ErrMsg Dim strTitle,strAddress,addTime Dim AllHits,Introduce,filesize Dim HtmlFileUrl,HtmlFileName,strUrl Newasp.ReadChannel(ChannelID) ChannelRootDir

asp.net类序列化生成xml文件实例详解_实用技巧

本文实例讲述了asp.net类序列化生成xml文件的方法.分享给大家供大家参考,具体如下: 根据设计的需求需要开发多个商品的API 原XML文件如下: <urlset> <url> <loc>http://www.xxxxx.com/todaydetials.aspx?id=143</loc> <data> <display> <website>爱购114</website> <siteurl>ht

如何用Asp动态生成xml文件

xml|动态|生成xml 相关代码如下:FunctionReplaceChar(FstrSource)dimstrRetifIsNull(FstrSource)then FstrSource=""endifstrRet=Replace(FstrSource,"&","&")strRet=Replace(strRet,"<","<")strRet=Replace(strRet,&q

C#多个XML文件合并 然后生成一个新的XML文件代码怎么写

问题描述 读取多个xml文件然后合并生成一个新的XML文件代码怎么写大神给实际例子谢谢! 解决方案 解决方案二:没具体需求的?那我随便给你找个了啊解决方案三:本帖最后由 starfd 于 2015-11-04 12:36:49 编辑解决方案四:就是把所有的xml文件整合到一个里面解决方案五:那2楼的满足你了啊--就是读取出来然后Add给Root节点解决方案六:能发下具体代码例子吗解决方案七:2楼链接打开有具体代码--解决方案八:加我QQ远程帮我看看1587292914解决方案九:如果你的xml没

asp.net简单生成XML文件的方法_实用技巧

本文实例讲述了asp.net简单生成XML文件的方法.分享给大家供大家参考,具体如下: 方式一:直接使用DataSet SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Server=127.0.0.1;User ID=sa;Password=sa;Database=northwind;Persist Security Info=True"; conn.Open(); SqlDataAdapter da

asp.net下C#生成XML文件各种方法

XmlDocument保存文件  代码如下 复制代码 XmlDocument doc = new XmlDocument();             try             {                 doc.Load("new.xml");             }             catch             {                 XmlTextWriter xtw = new XmlTextWriter("new.xml&

An ASP Class for XML Data Transfer(vbs类生成xml文件),希望

有两文件:objXML.asp:测试文件clsXML.asp:vbs类文件代码:objXML.asp<%@ Language=VBScript %><% Option Explicit %><!--#INCLUDE FILE="clsXML.asp"--><%Dim objXML, strPath, strSet objXML = New clsXMLstrPath = Server.MapPath(".") & &

如何用ASP生成XML数据文档

一.必须弄清楚最终需要的是什么 我们通过asp或其他动态编程语言,最终需要的是XML格式的数据,这点和XML数据所在的文件载体无关,它可以是实实在在的XML文件,比如:http://www.dw8.cn/common/dw8.xml .也可以为asp文档,比如:http://www.cnbruce.com/blog/rss2.asp 他们都是XML数据的体现,为了实现XML数据的动态,所以需要使用到动态编程语言,比如ASP来实现生成它. 二.如何生成动态的XML文档 如果是生成XML文件,介于动