Generate the XML content of the RSS aggregation page

Source: Internet
Author: User

 

RSS is a simple way to share content between websites. It is also called aggregate content. It is usually used for news websites. The website provides RSS output, which helps users discover updates to websites, A website user can use a client similarInformation ReaderAnd other news aggregation software that supports RSS.

RSS is a form based on XML, and all RSS must comply with the XML 1.0 specification published by W3C sites. For details, see the following rss2.0 specification.

RSS 2.0 specifications

BackgroundCodeWrite:

 

Background code

 1    String Xmlpath = @"  RSS. xml  "  ;  2       Protected   Void Page_load ( Object  Sender, eventargs E)  3   {  4           If (! Ispostback)  5   {  6               String Strpath = server. mappath ( "  .  " ) + Xmlpath; 7   8 Xmltextwriter writer = New  Xmltextwriter (strpath, encoding. utf8 );  9 Writer. Formatting = Formatting. indented;  10   Writer. writestartdocument ();  11 Writer. writecomment ( "  Read RSS  "  );  12 Writer. writestartelement ( "  RSS  "  );  13 Writer. writeattributestring ( "  Version  " , "  2.0  "  );  14 Writer. writestartelement ( "  Channel "  );  15 Writer. writestartelement ( "  Title  "  );  16 Writer. writecdata ( "  News-Sina news  "  );  17   Writer. writeendelement ();  18 Writer. writestartelement ("  Image  "  );  19 Writer. writestartelement ( "  Title  "  );  20 Writer. writecdata ( "  News Center  "  );  21   Writer. writeendelement (); 22 Writer. writeelementstring ( "  Link  " , "  Http://news.sina.com.cn  "  );  23 Writer. writeelementstring ( "  URL  " , "  Http://www.sinaimg.cn/home/deco/2009/0330/logo_home_news.gif "  );  24   Writer. writeendelement ();  25 Writer. writestartelement ( "  Description  "  );  26 Writer. writecdata ( "  News Center-news  "  );  27  Writer. writeendelement ();  28 Writer. writeelementstring ( "  Link  " , "  Http://roll.news.sina.com.cn/s/  "  );  29 Writer. writestartelement ( "  Language  "  );  30 Writer. writestring ( "  Zh-CN  "  );  31   Writer. writeendelement ();  32 Writer. writestartelement ( "  Copyright  "  );  33 Writer. writecdata ( "  Copyright 1996-2012 Sina Inc. All Rights Reserved "  );  34   Writer. writeendelement ();  35 Datatable dt = Readdata ();  36               For ( Int I = 0 ; I <DT. Rows. Count; I ++ )  37   {  38                   String Link = DT. Rows [I] [ "  Link  "  ]. Tostring ();  39                   String Title = DT. Rows [I] [ "  Title  "  ]. Tostring ();  40                   String Summary = DT. Rows [I] [ "  Summary  "  ]. Tostring (); 41                   String Author = DT. Rows [I] [ "  Author  "  ]. Tostring ();  42                   String Content = DT. Rows [I] [ "  Content  "  ]. Tostring ();  43                   String Published = DT. Rows [I] [ " Published  "  ]. Tostring ();  44 Writer. writestartelement ( "  Item  "  );  45 Writer. writestartelement ( "  Title  "  );  46   Writer. writestring (title ); 47   Writer. writeendelement ();  48 Writer. writeelementstring ( "  Link  "  , Link );  49 Writer. writeelementstring ( "  Author  "  , Author );  50 Writer. writeelementstring ( " Summary  "  , Summary );  51 Writer. writestartelement ( "  Description  "  );  52   Writer. writestring (content );  53   Writer. writeendelement ();  54 Writer. writeelementstring ( " Published  "  , Published );  55   Writer. writeendelement ();  56   }  57   Writer. writeendelement ();  58   Writer. writeendelement ();  59   Writer. writeenddocument ();  60   Writer. Flush (); 61   Writer. Close ();  62   63 Xmldocument document = New  Xmldocument ();  64   Document. Load (strpath );  65 Response. contenttype = "  Text/XML  "  ;  66  Document. Save (response. output );  67   }  68   }  69       Public  Datatable readdata ()  70   {  71           String Connectionstring = configurationmanager. connectionstrings [ "  Conn  " ]. Connectionstring;  72           Using (Sqlconnection con = New  Sqlconnection (connectionstring ))  73   {  74 Sqlcommand cmd = Con. createcommand ();  75 Cmd. commandtext = "  Select top 10 * from RSS where summary = 'financial news summary' order by [published] DESC  " ;  76 Sqldataadapter da = New  Sqldataadapter (CMD );  77 Dataset DS = New  Dataset ();  78   Da. Fill (DS );  79               If (DS = Null | Ds. Tables. Count <= 0 | Ds. Tables [ 0 ]. Rows. Count <= 0  )  80   {  81                   Return   New  Datatable ();  82   }  83               Return DS. Tables [ 0  ];  84   } 85 }

 

Because IE7 supports automatic parsing of RSS information, we can see the following webpage effect. Otherwise, we can see that it is only an XML code file.
Style:

RSS content reading

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.