日照市东港区创新电子技术中心
ndfweb.cn

使用asp编写rss文件范例


2009-01-17 11:40:13 (5922)


<%
xmlfile=server.MapPath("feed.xml")
set fso=server.CreateObject("Scripting.FileSystemObject")
set ifile=fso.CreateTextFile(xmlfile,True)

set objconn=Server.CreateObject("CustShop.ComClass1")
conn=objconn.DataSource()
set rs=Server.CreateObject("ADODB.Recordset")
str="select * from Cust_Shop"
rs.open str,conn,1,1
title="<?xml version=""1.0"" encoding=""GB2312""?>"
rssversion="<rss version=""2.0"">"
cssfile="<?xml-stylesheet type=""text/css"" href=""http://192.168.20.253/rss.css""?>"
ifile.Write(title)
ifile.Writeline(rssversion)
ifile.Writeline(cssfile)
  
   ifile.WriteLine("<channel>")
     ifile.writeLine("<title>")
     ifile.writeline("店铺信息")
     ifile.writeLine("</title>")
    
     ifile.writeLine("<link>")
     ifile.writeline("http://www.sohu.com")
     ifile.writeLine("</link>")
    
     ifile.writeLine("<Description>")
     ifile.writeline("店铺信息说明")
     ifile.writeLine("</Description>")

     ifile.writeLine("<language>")
     ifile.writeline("zh-cn")
     ifile.writeLine("</language>")

     if not rs.eof then
      while not rs.eof
         ifile.WriteLine("<item>")
          ifile.WriteLine("<title>")
            ifile.WriteLine(trim(rs("Shop_Name")))
          ifile.WriteLine("</title>")
          ifile.WriteLine("<link>")
            ifile.WriteLine("http://192.168.20.253/other/zhou/index.asp")
          ifile.WriteLine("</link>")
          ifile.WriteLine("<description>")
            ifile.WriteLine(trim(rs("Shop_About")))
          ifile.WriteLine("</description>")
          ifile.WriteLine("<pubdate>")
            ifile.WriteLine(date)
          ifile.WriteLine("</pubdate>")
         ifile.WriteLine("</item>")
         rs.movenext    
      wend
     end if
   ifile.WriteLine("</channel>")
   ifile.WriteLine("</rss>")
ifile.close
rs.close
response.Write("<a href=""feed.xml"">查看内容</a>")
%>

==============================================

<% @language="VBScript"%>

<%
Function readrss(xmlseed)
dim xmlDoc
dim http
Set http=Server.CreateObject("Microsoft.XMLHTTP")
http.Open "GET",xmlseed,False
http.send
Set xmlDoc=Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.Async=False
xmlDoc.ValidateOnParse=False
xmlDoc.Load(http.ResponseXML)
Set item=xmlDoc.getElementsByTagName("item")
if item.Length<=10 then
%>
<script language="JavaScript">
alert("对不起,该新闻条数已经少于10条新闻条数!");
</script>
<%
else
For i=0 To (item.Length-1)
Set title=item.Item(i).getElementsByTagName("title")
Set link=item.Item(i).getElementsByTagName("link")
Response.Write("<a href="""& link.Item(0).Text &""" target='_blank'>"& title.Item(0).Text &"</a><br>")
Next
end if
End Function
%>
<html>
<head>
<title>远程读取XML文件</title>
</head>
<body>
<%
call readrss("http://www.yangzhi.com/rss.asp")
%>
<br><br>

</body>
</html>

================================================

为你的网站,博客等添加rss聚合功能,给出rss.asp和rss.xml

两种的聚合代码

看过的朋友可帮忙顶哦,这些代码都是第一次发的,外面很多要不就是很复杂,看不懂,

要不就是不能用的,这里我修改了一下,写的时候也已经尽量简洁明了

以经测试,支持大部分聚合阅读器

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
%>
=======================================================
使用asp编写rss文件范例
原文CSDN的!呵呵,稍作改动!
    <%
xmlfile=server.MapPath("feed.xml")
set fso=server.CreateObject("Scripting.FileSystemObject")
set ifile=fso.CreateTextFile(xmlfile,True)

set objconn=Server.CreateObject("CustShop.ComClass1")
conn=objconn.DataSource()
set rs=Server.CreateObject("ADODB.Recordset")
str="select * from Cust_Shop"
rs.open str,conn,1,1
title="<?xml version=""1.0"" encoding=""GB2312""?>"
rssversion="<rss version=""2.0"">"
cssfile="<?xml-stylesheet type=""text/css"" href=""http://www.zcuu.com/rss.css""?>"
ifile.Write(title)
ifile.Writeline(rssversion)
ifile.Writeline(cssfile)
  
   ifile.WriteLine("<channel>")
     ifile.writeLine("<title>")
     ifile.writeline("资库信息")
     ifile.writeLine("</title>")
    
     ifile.writeLine("<link>")
     ifile.writeline("http://www.zcuu.com/")
     ifile.writeLine("</link>")
    
     ifile.writeLine("<Description>")
     ifile.writeline("资库信息说明")
     ifile.writeLine("</Description>")

     ifile.writeLine("<language>")
     ifile.writeline("zh-cn")
     ifile.writeLine("</language>")

     if not rs.eof then
      while not rs.eof
         ifile.WriteLine("<item>")
          ifile.WriteLine("<title>")
            ifile.WriteLine(trim(rs("Shop_Name")))
          ifile.WriteLine("</title>")
          ifile.WriteLine("<link>")
            ifile.WriteLine("http://www.zcuu.com/index.asp")
          ifile.WriteLine("</link>")
          ifile.WriteLine("<description>")
            ifile.WriteLine(trim(rs("Shop_About")))
          ifile.WriteLine("</description>")
          ifile.WriteLine("<pubdate>")
            ifile.WriteLine(date)
          ifile.WriteLine("</pubdate>")
         ifile.WriteLine("</item>")
         rs.movenext    
      wend
     end if
   ifile.WriteLine("</channel>")
   ifile.WriteLine("</rss>")
ifile.close
rs.close
response.Write("<a href=""feed.xml"">查看内容</a>")
%>
==================================================
了解更多请访问:http://www.ndfweb.cn/news-226.html
  NDF俱乐部
  国际域名注册
  建站咨询
合作伙伴:万网 | 新网 | 新网互联 NDF网站建设淘宝店 | 实用工具 | 外貿網站建設 | 联系我们
鲁公网安备 37110202000336号 Sitemap - RSSRSS订阅