How to create a summary of RSS content for a Web page dynamically

Source: Internet
Author: User
Tags format chr format definition generator client
rss| Create | dynamic | Web page 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.





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 of the RSS feed for creating a website column, 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.


Srsshead defines the basic elements of RSS. RSS feeds typically consist of 4 main elements:<channel>,<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>rss Create example </title>" & Scrlf


Srsshead = srsshead & <description> RSS Create example </description> "& Scrlf


srsshead = srsshead & "<link>http://1234.com/</link>" & Scrlf


srsshead = srsshead & "<language>zh-cn</language>" & Scrlf


srsshead = srsshead & "<docs>rss Create example r</docs>" & Scrlf


srsshead = srsshead & "<generator>rss generator by 1234.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, not rs.eof


Response.Write "<item>" & Scrlf


Response.Write "<title>" & RS ("F_topic") & "</title>" & Scrlf


Response.Write "<link>" & "http://www.1234.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 in the call format is: <a href= "http://www.1234.com/_news/RssFeed_news.asp" > Technology news





rss</a>. If you subscribe to this RSS with some client software, the URL for the subscription is





http://www.1234.com/_news/RssFeed_news.asp.





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.