sRssHead 定义 Rss 的基本元素。RSS feed 通常由 4 个主要元素构成:<channel>,&l t;image>,<item> 和 <textinput>。其中,<channel> 元素是必需的,<item> 元素至少要出现一次。<textinput> 和 <image> 元素是可选的,是否使用要视具体情况而定。
<channel> 元素包含 Channel(RSS feed 的来源)的一个简单描述。<title> 是频道的名称/标题;<link> 是与频道内容对应的包含了完整内容的那个网页的 URL;<description> 是与 <channel> 的内容有关的简单描述;<language> 代表语言。还有一些别的属性,不是太常用。
<item> 元素用于对数据库中的记录进行描述。<item> 一般有若干项,对应了一个 Rss feed 的数据集合。
<!-Filename:RssFeed_news.asp:-->
<% Option explicit %>
<!-- #include file="./conn.inc" -->
<%
Dim sSQL, rs, sCrLf, sXmlClear, sRssHead, sRssEnd
sCrLf = chr(13) & chr(10) ’回车+换行
sXmlClear = "<?xml version=’1.0’ encoding=’gb2312’?>" & sCrLf
sRssHead = "<rss version=’2.0’>" & sCrLf
sRssHead = sRssHead & "<channel>" & sCrLf
sRssHead = sRssHead & "<title> Why100000 </title>" & sCrLf
sRssHead = sRssHead & "<description> Why100000 </description>" & sCrLf
sRssHead = sRssHead & "<link>http://news.why100000.com/<;/link>" & sCrLf
sRssHead = sRssHead & "<language>zh-cn</language>" & sCrLf
sRssHead = sRssHead & "<docs>Why100000.COM News Center</docs>" & sCrLf
sRssHead = sRssHead & "<generator>Rss Generator By WWW.Why100000.COM</generator>" & sCrLf
sRssEnd = "</channel></rss>"
Response.CharSet="gb2312" ’数据集
Response.ContentType="text/xml" ’数据流格式定义
’输出:
Response.write sXmlClear
Response.write sRssHead
sSQL="select top 15 * from news order by sortid desc"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sSQL, s_Conn, 1, 1
if not (rs.eof and rs.bof) then
do while not rs.eof
response.write "<item>" & sCrLf
response.write "<title> " & rs("f_topic") & " </title>" & sCrLf
response.write "<link> " & "http://www.why100000.com/_news/show_a_new.asp?autoid="; &
rs("f_i_autoid") & " </link>" & sCrLf
response.write "<author> " & rs("f_author") & " </author>" & sCrLf
response.write "<pubDate> " & rs("f_datetime") & " </pubDate>" & sCrLf
response.write "</item>" & sCrLf & sCrLf
rs.movenext
loop
end if
rs.close
set rs=nothing
Response.write sRssEnd
%>
IE 中的调用格式是:<a href="http://www.why100000.com/_news/RssFeed_news.asp";>技术新闻
RSS</a>。如果用一些客户端软件订阅该 RSS,订阅的 Url 就是http://www.why100000.com/_news/RssFeed_news.asp。
<channel> 元素包含 Channel(RSS feed 的来源)的一个简单描述。<title> 是频道的名称/标题;<link> 是与频道内容对应的包含了完整内容的那个网页的 URL;<description> 是与 <channel> 的内容有关的简单描述;<language> 代表语言。还有一些别的属性,不是太常用。
<item> 元素用于对数据库中的记录进行描述。<item> 一般有若干项,对应了一个 Rss feed 的数据集合。
<!-Filename:RssFeed_news.asp:-->
<% Option explicit %>
<!-- #include file="./conn.inc" -->
<%
Dim sSQL, rs, sCrLf, sXmlClear, sRssHead, sRssEnd
sCrLf = chr(13) & chr(10) ’回车+换行
sXmlClear = "<?xml version=’1.0’ encoding=’gb2312’?>" & sCrLf
sRssHead = "<rss version=’2.0’>" & sCrLf
sRssHead = sRssHead & "<channel>" & sCrLf
sRssHead = sRssHead & "<title> Why100000 </title>" & sCrLf
sRssHead = sRssHead & "<description> Why100000 </description>" & sCrLf
sRssHead = sRssHead & "<link>http://news.why100000.com/<;/link>" & sCrLf
sRssHead = sRssHead & "<language>zh-cn</language>" & sCrLf
sRssHead = sRssHead & "<docs>Why100000.COM News Center</docs>" & sCrLf
sRssHead = sRssHead & "<generator>Rss Generator By WWW.Why100000.COM</generator>" & sCrLf
sRssEnd = "</channel></rss>"
Response.CharSet="gb2312" ’数据集
Response.ContentType="text/xml" ’数据流格式定义
’输出:
Response.write sXmlClear
Response.write sRssHead
sSQL="select top 15 * from news order by sortid desc"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sSQL, s_Conn, 1, 1
if not (rs.eof and rs.bof) then
do while not rs.eof
response.write "<item>" & sCrLf
response.write "<title> " & rs("f_topic") & " </title>" & sCrLf
response.write "<link> " & "http://www.why100000.com/_news/show_a_new.asp?autoid="; &
rs("f_i_autoid") & " </link>" & sCrLf
response.write "<author> " & rs("f_author") & " </author>" & sCrLf
response.write "<pubDate> " & rs("f_datetime") & " </pubDate>" & sCrLf
response.write "</item>" & sCrLf & sCrLf
rs.movenext
loop
end if
rs.close
set rs=nothing
Response.write sRssEnd
%>
IE 中的调用格式是:<a href="http://www.why100000.com/_news/RssFeed_news.asp";>技术新闻
RSS</a>。如果用一些客户端软件订阅该 RSS,订阅的 Url 就是http://www.why100000.com/_news/RssFeed_news.asp。