asp生成xml

 代码如下 复制代码

<%
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-10-03 04:44:02

asp生成xml的相关文章

如何用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文件,介于动

如何用ASP生成XML数据文档(RSS订阅)

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

asp生成xml文档实例程序代码

xml部分: <?xml version="1.0" encoding="gb2312"?> <bcastr> <item item_url='../uploadpic/2010052660955221.jpg' link='http://www.111cn.net' <itemtitle='01'></item> <item item_url='../uploadpic/2010052660981189.

ASP生成XML数据文档

一.必须弄清楚最终需要的是什么      我们通过asp或其他动态编程语言,最终需要的是XML格式的数据,这点和XML数据所在的文件载体无关,它可以是实实在在的XML文件,比如:/rss_1.xml .也可以为asp文档,比如:/rss.asp?id=42      他们都是XML数据的体现,为了实现XML数据的动态,所以需要使用到动态编程语言,比如ASP来实现生成它.      二.如何生成动态的XML文档      如果是生成XML文件,介于动态文档是ASP格式的,所以必须借助FSO进行XM

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")

asp生成xml的方法

 代码如下 复制代码 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML>  <HEAD>   <TITLE> 向xml中添加新节点 </TITLE>   <META NAME="Generator" CONTENT="EditPlus">   <META NAME="Aut

asp操作xml

ASP操作XML的类的说明: 可以完成ASP对XML节点的添加.删除.修改.清空. 进行上述操作,根据条件,操作类型包括:仅对第一个符合条件.及全部符合条件二种. 如: '将第一条件值替换成新值 'call xml.r_node("/blog/sorts/sort[id='2']/name","分lei2") '将全部条件值替换成新值 'call xml.r_nodes("/blog/sorts/sort[id='2']/name","

asp.net递归生成XML树的示例

asp.net|xml|生成xml|示例|递归 asp.net递归生成XML树的示例 代码: 以下是引用片段://CDepartmentInfo 类别实体类 //sjid :与大类别关联ID //space:只是一个标记 //strOpinion用来存放类名 string sjid = "0"; string space = "+"; string strOpinion = ""; string paths = @"E:\test&qu

直接生成XML的Google SiteMap代码[ASP版本]

google|sitemap|xml|生成xml ASP版本,需要空间的FSO支持使用方法就不说了 版主觉的可以,给个精第一次哦   CODE: [Copy to clipboard]   <%Server.ScriptTimeout=50000' sitemap_gen.asp' A simple script to automatically produce sitemaps for a webserver, in the Google Sitemap Protocol (GSP)' by