RSS (relly Simple Syndication) is a format used to describe and synchronize website content. It is currently the most widely used XML application. RSS builds a platform for rapid dissemination of information, which enables everyone to become a potential information provider. After an RSS file is published, the information contained in this RSS feed can be directly called by other sites, and because the data is in a standard XML format, it can also be used by other terminals and servers.
Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. webcontrols;
Using System. net;
Using System. IO;
Using System. xml;
Public Partial ClassDefault2: system. Web. UI. Page
{
Protected VoidPage_load (ObjectSender, eventargs E)
{
}< br> protected void btn_yd_click ( Object sender, eventargs E)
{< br> string url = txt_url.text;
//Send a URI request
Webrequest request = webrequest. Create (URL );
//Get URI response
Webresponse response = request. getresponse ();
//Get Response stream
Stream stream = response. getresponsestream ();
// Use an xmldocument object to store XML content in the stream
Xmldocument xdoc = New Xmldocument ();
// Xdoc. normalize ();
// Load a specified document from a specified stream
Xdoc. Load (Stream );
// Item Node Set
Xmlnodelist xnl = xdoc. selectnodes ( " RSS/channel/item " );
//Instantiate the item element entity class in RSS
Rssmodel item;
Ilist <rssmodel> items =NewList <rssmodel> ();
For (Int I = 0 ; I <xnl. Count; I ++)
{
Item = New Rssmodel ();
Xmlnode XN;
Xn = xnl. Item (I). selectsinglenode ( " Title " );
If (XN! = Null )
{
Item. Title = xn. innertext;
}
Xn = xnl. Item (I). selectsinglenode ("Link");
If(XN! =Null)
{
Item. Link = xn. innertext;
}
Xn = xnl. Item (I). selectsinglenode ( " Description " );
If (XN! = Null )
{
Item. Description = xn. innertext;
}
Items. Add (item );
}
Gridview1.datasource = items;
Gridview1.databind ();
}
}
Download source code