Merging Multiple RSS feeds

别来无恙 提交于 2019-12-11 02:18:25

问题


I’m very new to programming with RSS feeds to please forgive me if this sounds like a really general question.

Is it possible to take multiple RSS feeds from multiple sites and combine them as a single object to show to the end user?

For example, could I take the latest news headlines from one site, the latest blog updates from a totally different site and combine them into a single list to show the user?

I have seen this sort of question asked before and it seems like its possible, but the slight twist is I want to let the user add any feed that they want from any source

I’m looking to do this in ASP.NET

Many thanks!


回答1:


You can use the SyndicationFeed class to work with RSS feeds in .Net.

You probably want to do something like this (untested):

var allItems = new List<SyndicationItem>();

foreach(var feedUrl in whatever) { //In your list of urls
    using(var reader = XmlReader.Create(url))
        allItems.AddRange(SyndicationFeed.Load(reader).Items);
}

var newFeed = new SyndicationFeed(items);

//Do something with newFeed

You should add error handling in case one of the feeds is unavailable or invalid.




回答2:


It is possible, yes.

For a good example of this kind of thing in action, check out Yahoo! Pipes.

This would probably be a good application of LINQ to XML, but I'll leave the implementation up to you.



来源:https://stackoverflow.com/questions/1499101/merging-multiple-rss-feeds

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!