[Website generation series] blogroll

Source: Internet
Author: User
Blogroll provides the news aggregation function for websites and automatically reads rssfeeds Based on rssurl.
Although the RSS standard has long been formed, most sites do not comply with the RSS Standard Specification. Therefore, when writing the blogroll function, I only obtain the required attributes of RSS: title, Link, pubdate!
Class relationship diagram:


Rssitem: an RSS Element Object, including the title, Link, author, and release date.
Blogroll: operation class for obtaining rssitem and generating blogroll by rssurl.

Code : 1. rssitem
1 ///   <Summary>
2 /// RSS item instance
3 ///   </Summary>
4 Public   Class Rssitem
5 {
6 ///   <Summary>
7 /// Create a new <See CREF = "blogroll. API. rssitem"/> Instance with no parameters
8 ///   </Summary>
9 Public Rssitem (){}
10 ///   <Summary>
11 /// Title of rssitem
12 ///   </Summary>
13 Public   String Title { Get ; Set ;}
14 ///   <Summary>
15 /// Author of rssitem
16 ///   </Summary>
17 Public   String Author { Get ; Set ;}
18 ///   <Summary>
19 /// Link of rssitem
20 ///   </Summary>
21 Public   String Link { Get ; Set ;}
22 ///   <Summary>
23 /// Publish Date of rssitem
24 ///   </Summary>
25 Public Datetime pubdate { Get ; Set ;}
26 }

2. blogroll
1 ///   <Summary>
2 /// Bllogroll class
3 ///   </Summary>
4 Public   Sealed   Class Blogroll
5 {
6 ///   <Summary>
7 /// Load RSS items from the URL of RSS Feed
8 ///   </Summary>
9 ///   <Param name = "rssurl"> RSS URL </Param>
10 ///   <Param name = "num"> Numbers </Param>
11 ///   <Returns> </returns>
12 Public   Static List < Rssitem > Loadrssitems ( String Rssurl, Int Num)
13 {
14 List < Rssitem > Items =   New List < Rssitem > ();
15 WebClient WC =   New WebClient ();
16 WC. Encoding = Encoding. utf8;
17 Xelement XE =   Null ;
18 Using (Stream stream = WC. openread (rssurl ))
19 {
20 Xmltextreader xmlreader =   New Xmltextreader (Stream );
21
22 XE = Xelement. Load (xmlreader );
23 }
24
25 VaR Query = (
26 From Q In Xe. element ( " Channel " ). Elements ( " Item " )
27 Orderby datetime. parse (Q. element ( " Pubdate " ). Value) descending
28 Select New Rssitem
29 {
30 Title = Q. element ( " Title " ). Value,
31 Link = Q. element ( " Link " ). Value,
32 Pubdate = Datetime. parse (Q. element ( " Pubdate " ). Value)
33 }). Take (Num );
34
35 Return Query. tolist ();
36 }
37 }

Effect: OK. Use this method to aggregate the first 10 pieces of codeproject RSS (Asp.net) to generate blogroll:

Source code from csdn

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.