<p>What's a simple way to combine <strong>feed</strong> and <strong>feed2</strong>? I want the items from <strong>feed2</strong> to be added to <strong>feed</strong>. Also I want to avoid duplicates as <strong>feed</strong> might already have items when a question is tagged with both WPF and Silverlight.</p>

<pre><code>Uri feedUri = new Uri("http://stackoverflow.com/feeds/tag/silverlight");
XmlReader reader = XmlReader.Create(feedUri.AbsoluteUri);
SyndicationFeed feed = SyndicationFeed.Load(reader);    

Uri feed2Uri = new Uri("http://stackoverflow.com/feeds/tag/wpf");
XmlReader reader2 = XmlReader.Create(feed2Uri.AbsoluteUri);
SyndicationFeed feed2 = SyndicationFeed.Load(reader2);
</code></pre>

[{'answer_id': 79372, 'author': 'David Thibault', 'author_id': 5903, 'author_profile': 'https://Stackoverflow.com/users/5903', 'pm_score': 0, 'selected': False, 'text': '<p>If it\'s solely for stackoverflow, you can use this :<br>\n<a href="https://stackoverflow.com/feeds/tag/silverlight%20wpf">https://stackoverflow.com/feeds/tag/silverlight%20wpf</a><br>\nThis <strong>will</strong> do an union of the two tags.</p>\n\n<p>For a more general solution, I don\'t know. You\'d probably have to manually iterate the elements of the two feeds and join them together. You can compare the &lt;id> elements of &lt;entry>s to see if they are duplicates.</p>\n'}, {'answer_id': 79376, 'author': 'Frater', 'author_id': 14746, 'author_profile': 'https://Stackoverflow.com/users/14746', 'pm_score': 1, 'selected': False, 'text': "<p>Well, one possibility is to create a new syndication feed that is a clone of the first feed, and then simply iterate through each post on the second one, check the first for its existence, and add it if it doesn't exist.</p>\n\n<p>Something along the lines of:</p>\n\n<pre><code>SyndicationFeed newFeed = feed.clone;\nforeach(SyndicationItem item in feed2.items)\n{\n  if (!newFeed.contains(item))\n    newFeed.items.Add(item);\n}\n</code></pre>\n\n<p>might be able to do it.  It looks like 'items' is a simple enumberable list of syndication items, so theres not reason you can't simply add them.</p>\n"}, {'answer_id': 86322, 'author': 'Michael Brown', 'author_id': 14359, 'author_profile': 'https://Stackoverflow.com/users/14359', 'pm_score': 5, 'selected': True, 'text': '<p>You can use LINQ to simplify the code to join two lists (don\'t forget to put System.Linq in your usings and if necessary reference System.Core in your project) Here\'s a Main that does the union and prints them to console (with proper cleanup of the Reader).</p>\n\n<pre><code>using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Xml;\nusing System.ServiceModel.Syndication;\n\nnamespace FeedUnion\n{\n    class Program\n    {\n        static void Main(string[] args)\n        {\n            Uri feedUri = new Uri("http://stackoverflow.com/feeds/tag/silverlight"); \n            SyndicationFeed feed;\n            SyndicationFeed feed2;\n            using(XmlReader reader = XmlReader.Create(feedUri.AbsoluteUri))\n            {\n                feed= SyndicationFeed.Load(reader); \n            }\n            Uri feed2Uri = new Uri("http://stackoverflow.com/feeds/tag/wpf"); \n            using (XmlReader reader2 = XmlReader.Create(feed2Uri.AbsoluteUri))\n            {\n            feed2 = SyndicationFeed.Load(reader2);\n            }\n            SyndicationFeed feed3 = new SyndicationFeed(feed.Items.Union(feed2.Items));\n            StringBuilder builder = new StringBuilder();\n            using (XmlWriter writer = XmlWriter.Create(builder))\n            {\n                feed3.SaveAsRss20(writer);\n                System.Console.Write(builder.ToString());\n                System.Console.Read();\n            }\n        }\n    }\n}\n</code></pre>\n'}, {'answer_id': 8916265, 'author': 'rasx', 'author_id': 22944, 'author_profile': 'https://Stackoverflow.com/users/22944', 'pm_score': 0, 'selected': False, 'text': '<p>I\'ve turned today\'s accepted answer into a unit test just to explore this slightly:</p>\n\n<pre><code>    [TestMethod]\n    public void ShouldCombineRssFeeds()\n    {\n        //reference: http://stackoverflow.com/questions/79197/combining-two-syndicationfeeds\n\n        SyndicationFeed feed;\n        SyndicationFeed feed2;\n\n        var feedUri = new Uri("http://stackoverflow.com/feeds/tag/silverlight");\n        using(var reader = XmlReader.Create(feedUri.AbsoluteUri))\n        {\n            feed = SyndicationFeed.Load(reader);\n        }\n\n        Assert.IsTrue(feed.Items.Count() &gt; 0, "The expected feed items are not here.");\n\n        var feed2Uri = new Uri("http://stackoverflow.com/feeds/tag/wpf");\n        using(var reader2 = XmlReader.Create(feed2Uri.AbsoluteUri))\n        {\n            feed2 = SyndicationFeed.Load(reader2);\n        }\n\n        Assert.IsTrue(feed2.Items.Count() &gt; 0, "The expected feed items are not here.");\n\n        var feedsCombined = new SyndicationFeed(feed.Items.Union(feed2.Items));\n\n        Assert.IsTrue(\n            feedsCombined.Items.Count() == feed.Items.Count() + feed2.Items.Count(),\n            "The expected number of combined feed items are not here.");\n\n        var builder = new StringBuilder();\n        using(var writer = XmlWriter.Create(builder))\n        {\n            feedsCombined.SaveAsRss20(writer);\n            writer.Flush();\n            writer.Close();\n        }\n\n        var xmlString = builder.ToString();\n\n        Assert.IsTrue(new Func&lt;bool&gt;(\n            () =&gt;\n            {\n                var test = false;\n\n                var xDoc = XDocument.Parse(xmlString);\n                var count = xDoc.Root.Element("channel").Elements("item").Count();\n                test = (count == feedsCombined.Items.Count());\n\n                return test;\n            }\n        ).Invoke(), "The expected number of RSS items are not here.");\n    }\n</code></pre>\n'}, {'answer_id': 17917480, 'author': 'Manjit', 'author_id': 2629183, 'author_profile': 'https://Stackoverflow.com/users/2629183', 'pm_score': 0, 'selected': False, 'text': '<pre><code>        //Executed and Tested :)            \n        using (XmlReader reader = XmlReader.Create(strFeed))\n        {\n            rssData = SyndicationFeed.Load(reader);\n            model.BlogFeed = rssData; ;\n        }\n        using (XmlReader reader = XmlReader.Create(strFeed1))\n        {\n            rssData1 = SyndicationFeed.Load(reader);\n            model.BlogFeed = rssData1;\n        }\n\n        SyndicationFeed feed3 = new SyndicationFeed(rssData.Items.Union(rssData1.Items));\n        model.BlogFeed = feed3;           \n        return View(model);\n</code></pre>\n'}, {'answer_id': 35239636, 'author': 'Pherekles', 'author_id': 4565121, 'author_profile': 'https://Stackoverflow.com/users/4565121', 'pm_score': 0, 'selected': False, 'text': "<p>This worked fine for me:</p>\n\n<pre><code>// create temporary List of SyndicationItem's\nList&lt;SyndicationItem&gt; tempItems = new List&lt;SyndicationItem&gt;();\n\n// add all feed items to the list\ntempItems.AddRange(feed.Items);\ntempItems.AddRange(feed2.Items);\n\n// remove duplicates with Linq 'Distinct()'-method depending on yourattributes\n\n// add list without duplicates to 'feed2'\nfeed2.Items = tempItems\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/79197', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1133/']