Fetch data from RSS and bind to a asp control
I have to display weather details of a perticular city in a asp control as a widget. I hope i can get the weather details as rss feed data. Here how to bind this data to a asp cont开发者_Python百科rol?. I need to show next 10 days weather details also.
Try the below code. You can use your desired attributes. I used Date, Title, Description, Link
internal class RssItem
{
public DateTime Date;
public string Title;
public string Description;
public string Link;
}
XmlDocument xmlDoc = new XmlDocument();
private Collection<RssItem> feedItems = new Collection<RssItem>();
xmlDoc.Load("URL of the RSS Feeds");
ParseRssItems(xmlDoc);
private void ParseRssItems(XmlDocument xmlDoc)
{
this.feedItems.Clear();
foreach (XmlNode node in xmlDoc.SelectNodes("rss/channel/item"))
{
RssItem item = new RssItem();
this.ParseDocElements(node, "title", ref item.Title);
this.ParseDocElements(node, "description", ref item.Description);
this.ParseDocElements(node, "link", ref item.Link);
string date = null;
this.ParseDocElements(node, "pubDate", ref date);
DateTime.TryParse(date, out item.Date);
this.feedItems.Add(item);
}
}
You could deserialize the RSS xml to an object and databind a repeater to the items collection in that object. Simple and works.
Use RSStoolkit Easy to use and flexible Use this sample
精彩评论