How to receive RSS news and implement online subscription/display (with full code) _ ax

Source: Internet
Author: User

Finally, I did a good job. In fact, I didn't do it yesterday. Today I realized my promise the day before yesterday.
I made a promise, but I didn't set the time for this promise to come true. ______ I realized that I was getting more and more talented !! Wahaha ~~~
Let's look back. RSS is so simple. All enemies are paper tigers !!!!

[Help] I found through tests that it would take more than one second to obtain the RSS feed for subscribing to my blog. It would take up to 12 seconds. Who has an optimization method? Do I have to fetch n multiple subscription times back, store them in the database, and read them from the database when I view the RSS subscription ???

[Conclusion] This process is very simple,
① Create an httpwebrequest request to obtain the RSS content to be subscribed to. The format is XML,
② Parse RSS using the xmldocument class,
③ Display the part you want after parsing.
From this, I got to know the httpwebrequest/xmldocument classes and their methods. benefiting from ing ....
I would like to thank my colleagues for their help.CodeMost of them are plagiarized!
I cannot publish his name to the world without permission!

[Full code] the front-end page does not need to be changed. The variable name is missing my pen name: ax/axzxhz
Using system;
Using system. collections;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. htmlcontrols;
Using system. net;
Using system. IO;
Using system. xml;
Namespace woall. Test
{
/// <Summary>
/// Summary of arss.
/// Axzhz write in Beijing
/// </Summary>
Public class arss: system. Web. UI. Page
{
Protected system. Web. UI. webcontrols. Label label1;

Private void page_load (Object sender, system. eventargs E)
{
Datetime dt0 = datetime. now;
// Create an httpwebrequest
Httpwebrequest request = (httpwebrequest) webrequest. Create (" Http://www.cnblogs.com/AXzhz/CommentsRSS.aspx ");
Httpwebresponse RSS = (httpwebresponse) request. getresponse ();
Streamreader sr = new streamreader (RSS. getresponsestream (), system. Text. encoding. getencoding ("gb2312 "));

// get the XML file. Remember to close it.
string xml = sr. readtoend ();
Sr. close ();
RSS. close ();
datetime dt1 = datetime. now;
// check what is retrieved.
response. write (" the XML string we retrieved is shown below:
" + server. htmlencode (XML) + "
");

 // Split the XML string for display
Xmldocument rssdoc = new xmldocument ();
Rssdoc. loadxml (XML );
// You can retrieve different contents by using node logos, such as RSS, channel, and item.
Xmlnodelist NL = rssdoc. selectnodes ("RSS/channel/item/Title ");
Response. Write ("<font color = Red> start to display the title of the News subscription: <br> </font> ");
Foreach (xmlnode xnl in NL)
{
// How to display such content depends on you
Response. Write (xnl. innertext + "<br> ");
}
Datetime dt2 = datetime. now;

Response. Write ("<br> get RSS:" + (dt1-dt0) + "<br> ");
Response. Write ("display time:" + (dt2-dt1) + "<br> ");
Response. Write ("Total time:" + (dt2-dt0 ));
}

# Code generated by region web Form Designer
Override protected void oninit (eventargs E)
{
//
// Codegen: This call is required by the ASP. NET web form designer.
//
Initializecomponent ();
Base. oninit (E );
}

/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void initializecomponent ()
{
This. Load + = new system. eventhandler (this. page_load );

}
# Endregion
}
}

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.