开发者

How do I consume a RSS feed in ASP.Net webapp

I need to create a web app which will consume RSS feed. Do I need to go in the same way as ,

Create a XMLReader , Load XML , Parse it , then Bind the values to different fields. Is there any other way to开发者_如何学运维 consume the web RSS feed and display it on my aspx page.


The steps you describe are pretty much what you have to do, load the XML, parse it, then render the output. However, there are some APIs that make it pretty easy to achieve this task. For example Linq-to-XML makes parsing an RSS feed almost trivial. For example, this code parses and RSS feed, creating a FeedItemModel for each item:

var rssFeed = XDocument.Parse(yourRSSString);
var items = from item in rssFeed.Descendants("item")
            select new FeedItemModel()
                    {
                        Title = item.Element("title").Value,
                        DatePublished = DateTime.Parse(item.Element("pubDate").Value),
                        Url = item.Element("link").Value,
                        Description = item.Element("description").Value
                    };


I've written a blog post on this which will step you through the process.

http://www.wduffy.co.uk/blog/how-to-consume-an-xml-feed-in-aspnet-rss/


There is an RSS toolkit available on line. you can try using it if you want.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜