Search code examples
c#rss

How to get only Items that are within specific Category from RSS Feed


Im writing an RSS-Reader (sort of) that should only output Items that are within of a Category named "FF - Titel-Themen" (Link to the RSS Feed is here). I have search now for quite a time and couldn't find anything and because i´m new to this whole RSS with C# thing its not making anything easier. I hope my question make sense...


Solution

  • XmlReader xmlReader = XmlReader.Create("feed url / xml file");
    SyndicationFeed RSSFeed = SyndicationFeed.Load(xmlReader);
    xmlReader.Close();
    List<string> AllCategories = new List<string>();
    foreach (SyndicationItem SyndicationItem in RSSFeed.Items)
            {
                foreach (SyndicationCategory category1 in SyndicationItem.Categories)
                {
                    if (!Categories_All.Contains(category1.Name))
                    {
                        Categories_All.Add(category1.Name);
                    }
                }
            }
    SyndicationCategory SelectedCategory = new SyndicationCategory("Your specific Category");
            foreach (SyndicationItem SyndicationItem in RSSFeed.Items)
            {
                foreach (SyndicationCategory syndicationCategory in SyndicationItem.Categories)
                {
                    if (syndicationCategory.Name == SelectedCategory.Name)
                    {
                        // DO STUFF WHAT YOU WANT TO DO WITH THE ITEMS
                    }
                }
            }