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