RSS


 Fetch RSS-feed

This is a very simple code sample of how to consume an RSS feed. We need to set the DtD to ignore in XML settings because some feeds do not validate well and we still want to consume them.

using System.ServiceModel.Syndication;
using System.Xml;
using System.Xml.Linq;

private static XmlReaderSettings xmlSettings;

public RssFetcher()
{
    xmlSettings = new XmlReaderSettings()
    {
        DtdProcessing = DtdProcessing.Ignore,
        CheckCharacters = false,
    };
}

public void GetItems(){
    var reader = XmlReader.Create(url, xmlSettings);
    var feed = SyndicationFeed.Load(reader);

    foreach (var item in feed.Items)
    {
         //Consume the item here.
    }
}

 

 

 

 


Published: 2016-08-25