欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

适合所有网站的rss和xml聚合功能asp代码

程序员文章站 2023-09-06 16:20:23
rss.asp格式的 下面代码保存为rss.asp 复制代码 代码如下: <% strurl...
rss.asp格式的
下面代码保存为rss.asp
复制代码 代码如下:

<!--#include file="conn.asp"-->
<%
strurl = "http://" & request.servervariables("server_name") & _
left(request.servervariables("script_name"),len(request.servervariables("script_name"))-len("/rss.asp")) //中的/rss.asp为你的该文件名

sql="select top 100 * from [表名] order by id desc" //根据自己实际修改,top 100 为最新100条,自己修改,同时可以增加查询条件,如where xxx=1....
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
response.contenttype="text/xml"
response.write "<?xml version=""1.0"" encoding=""gb2312"" ?>" & vbcrlf
response.write "<rss version=""2.0"">" & vbcrlf
response.write "<channel>" & vbcrlf
response.write "<title>xxx.com rss feed</title>" & vbcrlf
response.write "<link>" & strurl & "</link>" & vbcrlf
response.write "<language>zh-cn</language>" & vbcrlf
response.write "<copyright>an rss feed for xxx.comcopyright>" & vbcrlf
while not rs.eof
response.write "<item>" & vbcrlf
response.write "<title><![cdata[" & rs("title") & "]]></title>" & vbcrlf
response.write "<link>"&strurl"/xxxx.asp?id="&rs("id")"</link>" & vbcrlf
response.write "<description><![cdata[" & rs("主题字段") & "<br />" & rs("内容字段") & "<br /><br />]]></description>" & vbcrlf
response.write "<pubdate>" & return_rfc822_date(rs("时间字段"),"gmt") & "</pubdate>" & vbcrlf
response.write "</item>" & vbcrlf
rs.movenext
wend
response.write "</channel>" & vbcrlf
response.write "</rss>" & vbcrlf
rs.close
set rs=nothing

function return_rfc822_date(byval mydate, byval timezone)
dim myday, mydays, mymonth, myyear
dim myhours, myminutes, myseconds

mydate = cdate(mydate)
myday = enweekdayname(mydate)
mydays = right("00" & day(mydate),2)
mymonth = enmonthname(mydate)
myyear = year(mydate)
myhours = right("00" & hour(mydate),2)
myminutes = right("00" & minute(mydate),2)
myseconds = right("00" & second(mydate),2)


return_rfc822_date = myday", "& _
mydays" "& _
mymonth" "& _
myyear" "& _
myhours":"& _
myminutes":"& _
myseconds" "& _
" " & timezone
end function

function enweekdayname(inputdate)
dim result
select case weekday(inputdate,1)
case 1:result="sun"
case 2:result="mon"
case 3:result="tue"
case 4:result="wed"
case 5:result="thu"
case 6:result="fri"
case 7:result="sat"
end select
enweekdayname = result
end function

function enmonthname(inputdate)
dim result
select case month(inputdate)
case 1:result="jan"
case 2:result="feb"
case 3:result="mar"
case 4:result="apr"
case 5:result="may"
case 6:result="jun"
case 7:result="jul"
case 8:result="aug"
case 9:result="sep"
case 10:result="oct"
case 11:result="nov"
case 12:result="dec"
end select
enmonthname = result
end function
%>

rss.xml格式的
复制代码 代码如下:

<!--#include file="conn.asp"-->
<%
strurl = "http://" & request.servervariables("server_name") & _
left(request.servervariables("script_name"),len(request.servervariables("script_name"))-len("/rss.asp"))
dim foolcat,js
set js = server.createobject("adodb.recordset")
sql = "select * from [表名] order by id asc"
set js = conn.execute (sql)

foolcat = foolcat + "<?xml version=""1.0"" encoding=""utf-8"" ?>"
foolcat = foolcat + "<rss version=""2.0"">"
foolcat = foolcat + "<channel>"
foolcat = foolcat + "<title>xxx.com xml feed</title>"
foolcat = foolcat + "<link>" & strurl & "</link>"
foolcat = foolcat + "<language>zh-cn</language>"
foolcat = foolcat + "<copyright>an xml feed for xxx.com</copyright>"
do until js.eof
foolcat = foolcat + "<item>"
foolcat = foolcat + "<title><![cdata[" & rs("主题字段") & "]]></title>"
foolcat = foolcat + "<description><![cdata[" & rs("主题字段") & "<br />" & rs("内容字段") & "<br /><br />]]></description>"
foolcat = foolcat + "<link>" & strurl & "/xxx.asp?id="&rs("id字段")"</link>"
foolcat = foolcat + "<pubdate>" & rs("时间字段") & "</pubdate>"
foolcat = foolcat + "</item>"
js.movenext
loop
js.close
set js = nothing
foolcat = foolcat + "</channel>"
foolcat = foolcat + "</rss>"
foolcat = "" + foolcat + ""
foolcat = "" & foolcat & ""
folderpath = server.mappath("/")
set fso = server.createobject("scripting.filesystemobject")
set fout = fso.createtextfile(folderpath"\rss.xml")
fout.writeline foolcat
fout.close
set fout = nothing
conn.close
set conn = nothing
%>