Create a Web site RSS format Content summary with Asp+access

Source: Internet
Author: User
Tags format chr format definition generator version client access
access|asp+|rss| Create |access|rss RSS is a "lightweight, versatile, extensible metadata description and joint promotion format," or 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 an XML-formatted document, then 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.

The method of calling an RSS feed in IE is no different from a normal link, in the form of:
<a type= "Application/rss+xml" href= "rssfeed.asp" >rss description </a>
One of 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 web site, the file name is rssfeed_news.asp.
Where the variable sxmlclear is used to declare that the resulting document is an XML-formatted document that is optional to maintain backward compatibility with older versions of XML.

Srsshead defines the basic elements of RSS. RSS feeds typically 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. The <textinput> and <image> elements are optional and are to be used depending on the circumstances.
The <channel> element contains a simple description of the channel (the source of the RSS feed). <title> is the name/title;<link> of the channel is a simple description of the content of <channel>, which corresponds to the content of the Web page containing the contents of the url;<description>; <language> representative language. There are other attributes that are not too often used.
The <item> element is used to describe the records in the database. <item> typically has several items that correspond to a collection of data for an RSS feed.

<!-Filename:RssFeed_news.asp:-->
<% Option Explicit%>
<!--#include file= "./conn.inc"-->

<%
Dim sSQL, RS, Scrlf, Sxmlclear, Srsshead, Srssend
SCRLF = CHR & Chr (10) ' Carriage return + linefeed

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" 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 as 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
%>



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.