开发者

Fetch data from RSS and bind to a asp control

开发者 https://www.devze.com 2023-03-07 15:20 出处:网络
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 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

0

精彩评论

暂无评论...
验证码 换一张
取 消