Use Asp+access to create a Web site RSS format Content Summary _xml/rss

Source: Internet
Author: User
Tags format definition generator
RSS is a "lightweight, multi-purpose, extensible metadata description and joint promotion format", can also be understood as a specification. It is an XML format that is used to provide selective and aggregated content-consolidation clients; Web content. Today, many sites start by creating RSS feeds to provide content integration services to viewers, providing news, site content updates, and so on. Visitors can easily get these organizations and aggregated information through some client software.


So, how do you create an RSS feed on our own web site? Below I take asp+access as an example to introduce.


since RSS is a document in XML format, we should be able to filter the data in the background database according to the conditions, and then generate the data stream in XML format through ASP, and finally send it to the client for browsing.

The selection and collection of
data is the forte of ASP, and the key is how to generate the data stream in XML format. In fact, the ASP has its own solution, is to write the data on the response object of the ContentType attribute to define. If response.  The value of ContentType is "Text/xml", and the data stream in XML format is sent to the viewer.


in IE browser to invoke the RSS feed method and the common link is no different, the format is:


<a type= "Application/rss+xml" href= "rssfeed.asp" >rss description </a>


of which the type= "Application/rss+xml" plus does not add as if there is no difference.





The following program segment is the source code for the RSS feed for the "Technical News" section of the "100,000 Why" (http://www.why100000.com/) of my website


, the file name is rssfeed_news.asp.


where the variable sxmlclear is used to declare the resulting document as an XML-formatted document, the declaration is optional to maintain backward compatibility with older versions of XML


sex.





Srsshead defines the basic elements of RSS. RSS feeds usually consist of 4 main elements: <channel>,&l t;image>,<item> and


<textinput>. Where the,<channel> element is a required,<item> element must appear at least once. <textinput> and <image> elements are optional,

Whether the
is used depends on the specific circumstances.

The
<channel> element contains a simple description of the channel (the source of the RSS feed). <title> is the channel's name/title;<link> is with the channel content on

The url;<description> of the page that
should contain the complete content is a simple description;&lt;language&gt; representative language related to the content of &lt;channel&gt;.


There are other attributes that are not too often used.


The &lt;item&gt; element is used to describe the records in the database.  &lt;item&gt; typically has several items that correspond to a collection of data for an RSS feed.


Copy Code code as follows:



&lt;!-Filename:RssFeed_news.asp:--&gt;


&lt;% Option Explicit%&gt;


&lt;!--#include file= "./conn.inc"--&gt;





&lt;%


Dim sSQL, RS, Scrlf, Sxmlclear, Srsshead, Srssend


SCRLF = CHR &amp; Chr (10) ' carriage return + linefeed





sxmlclear = "&lt;?xml version= ' 1.0 ' encoding= ' gb2312 '?&gt; '" &amp; Scrlf





srsshead = "&lt;rss version= ' 2.0 ' &gt;" &amp; Scrlf


Srsshead = srsshead &amp; "&lt;channel&gt;" &amp; Scrlf


srsshead = srsshead &amp; "&lt;title&gt; Why100000 &lt;/title&gt;" &amp; Scrlf


srsshead = srsshead &amp; "&lt;description&gt; Why100000 &lt;/description&gt;" &amp; Scrlf


srsshead = srsshead &amp; "&lt;link&gt;http://news.why100000.com/&lt;;/link&gt;" &amp; Scrlf


srsshead = srsshead &amp; "&lt;language&gt;zh-cn&lt;/language&gt;" &amp; Scrlf


srsshead = srsshead &amp; "&lt;docs&gt;why100000.com News center&lt;/docs&gt;" &amp; Scrlf


Srsshead = srsshead &amp; "&lt;generator&gt;rss generator by www.why100000.com&lt;/generator&gt;" &amp; SCrLf





srssend = "&lt;/channel&gt;&lt;/rss&gt;"





response.charset= "gb2312" DataSet


response.contenttype= "text/xml" Data flow format definition





' Output:


Response.Write Sxmlclear


Response.Write Srsshead





ssql= "SELECT top * 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, not rs.eof


Response.Write "&lt;item&gt;" &amp; Scrlf


Response.Write "&lt;title&gt;" &amp; RS ("F_topic") &amp; "&lt;/title&gt;" &amp; Scrlf


Response.Write "&lt;link&gt;" &amp; "http://www.why100000.com/_news/show_a_new.asp?autoid="; &amp;





rs ("F_i_autoid") &amp; "&lt;/link&gt;" &amp; Scrlf


Response.Write "&lt;author&gt;" &amp; RS ("F_author") &amp; "&lt;/author&gt;" &amp; Scrlf


Response.Write "&lt;pubDate&gt;" &amp; RS ("F_datetime") &amp; "&lt;/pubDate&gt;" &amp; Scrlf


Response.Write "&lt;/item&gt;" &amp; Scrlf &amp; Scrlf


Rs.movenext


Loop


End If


Rs.close


Set rs=nothing





Response.Write Srssend


%&gt;





IE in the call format is: &lt;a href= "http://www.why100000.com/_news/RssFeed_news.asp";&gt; Technical News





rss&lt;/a&gt;. If you subscribe to this RSS with some client software, the URL for the subscription is http://www.why100000.com/_news/RssFeed_news.asp.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.