The source code of an RSS reader is not exclusive!

Source: Internet
Author: User

Recently, a friend asked me to help me get an online RSS reader. I found a lot of information and didn't have a complete project file. I just got

Share the first version with you.

You can enter a standard RSS address at will
CodeContains detailed annotations. This is just a simple Asp.net example.ProgramSource code. Other functions can be expanded on your own.

Public   Void Processrssitem ( String Rssurl)

{
// Use a string rssurl as its parameter. This string contains the URL of RSS. It uses the value of rssurl to create a webrequest item
System. net. webrequest myrequest = System. net. webrequest. Create (rssurl );

// The request response will be put in a webresponse object.
System. net. webresponse myresponse = Myrequest. getresponse ();

// This webresponse object is used to create a stream to retrieve XML values.
System. Io. Stream rssstream = Myresponse. getresponsestream ();

// Use an xmldocument object to store the XML content in the stream. The xmldocument object is used to call XML content.
System. xml. xmldocument rssdoc =   New System. xml. xmldocument ();
Rssdoc. Load (rssstream );

// Items should be in RSS/channel. Use XPath to create an item node list as follows
System. xml. xmlnodelist rssitems = Rssdoc. selectnodes ( " RSS/channel/item " );

String Title =   "" ;
String Link =   "" ;
String Description =   "" ;

For ( Int I =   0 ; I < Rssitems. Count; I ++ )
{

System. xml. xmlnode rssdetail;

Rssdetail = Rssitems. Item (I). selectsinglenode ( " Title " );
If (Rssdetail ! =   Null )
{
Title=Rssdetail. innertext;
}
Else
{
Title= "";
}

Rssdetail = Rssitems. Item (I). selectsinglenode ( " Link " );
If (Rssdetail ! =   Null )
{
Link=Rssdetail. innertext;
}
Else
{
Link= "";
}

Rssdetail = Rssitems. Item (I). selectsinglenode ( " Description " );
If (Rssdetail ! =   Null )
{
Description=Rssdetail. innertext;
}
Else
{
Description= "";
}

Response. Write ( " <P> <B> <a href =' "   + Link +   " 'Target = 'new'> "   + Title +   " </A> </B> "   + Description +   " </P> " );

}

}

// Read RSS
Protected   Void Btnread_click ( Object Sender, eventargs E)
{
String Rssurl = Txturl. Text. Trim ();
Literal1.text =   " <Font size = 5> <B> site: "   + Rssurl +   " </B> </font> <br/> " ;
Processrssitem (rssurl );
}

Project source code

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.