Combining multiple RSS feeds

I have successfully used "union" as described here to join two RSS feeds in a C # project, but we have a scenario where we could have accurate to hundreds of RSS feeds to combine. What would be the best way with this number of feeds?

+2


source to share


2 answers


I would use SelectMany()

(shown here via LINQ) to flatten the channels into one sequence, then use Distinct()

to filter out the duplicates you've already seen:

var feeds = new[] {
    "http://stackoverflow.com/feeds/tag/silverlight",
    "http://stackoverflow.com/feeds/tag/wpf"
};

var items = from url in feeds
            from xr in XmlReader.Create(url).Use()
            let feed = SyndicationFeed.Load(xr)
            from i in feed.Items
            select i;
var newFeed = new SyndicationFeed(items.Distinct());

      



Use()

is an extension method described here to clean up the reader after using it. You may also need to define your own IEqualityComparer<SyndicationItem>

to use with Distinct()

.

+2


source


  • Create XML document with one root node
  • Read the children of the root node of all secondary rss feeds
  • Add these children to a new root node xml document


To work around the "node already belongs to another document" problem, simply take the Inner XML from the root node and add it to the Inner XML of the aggregated document.

0


source







All Articles