[英]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. 我必须在asp控件中以小部件的形式显示特定城市的天气详细信息。 I hope i can get the weather details as rss feed data. 我希望我可以将天气详细信息作为rss feed数据获取。 Here how to bind this data to a asp control?. 在这里,如何将这些数据绑定到ASP控件? I need to show next 10 days weather details also. 我还需要显示未来10天的天气详细信息。
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. 您可以将RSS xml反序列化为对象,然后将中继器与该对象中的项目集合绑定。 Simple and works. 简单而有效。
使用RSStoolkit易于使用且灵活使用此示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.