This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

Network and Internet
.NET 3.5+

Reading RSS and Atom Syndication Feeds

RSS and Atom feeds provide a standardised means of providing syndicated content via the Internet. The feeds publish XML documents that can be downloaded by web sites that aggregate stories from several places or into feed reader software.

Reading Feed Items

Usually the reason for reading a feed is to obtain the list of articles or stories from within. These are provided as a collection of SyndicationItem objects in the SyndicationFeed's Items property. One object is created for each story in the feed. The following code demonstrates some of the item properties by outputting all of the articles from the BlackWasp RSS feed downloaded earlier.

foreach (SyndicationItem item in feed.Items)
    Console.ForegroundColor = ConsoleColor.White;
    Console.ForegroundColor = ConsoleColor.Gray;
    Console.ForegroundColor = ConsoleColor.Green;

SyndicationItem Properties

The SyndicationItem class provides a number of properties. As with the feed object, many of these are optional and their contents can vary according to the type of feed being read. You should check that the properties are not null before trying to access their sub-properties.

The key properties that you will use when reading a feed are:

  • Authors. A collection of SyndicationPerson objects containing the authors of the story.
  • Categories. A collection of SyndicationCategory objects that describe the categories for the item.
  • Contributors. A collection of SyndicationPerson objects containing the contributors to the story.
  • Content. The content of the story. This is usually populated when reading Atom feeds but not with RSS feeds. You should always check both the Content and Summary properties to ensure that you obtain the content required.
  • Copyright. Holds copyright information as a TextSyndicationContent object.
  • Id. A string containing a unique identifier for the item.
  • LastUpdatedTime. The time that the story was last updated as a DateTimeOffset.
  • Links. News feed items can include a number of URLs, including a link to the story itself. These are held in a collection of SyndicationLink objects.
  • PublishDate. The date that the story was published as a DateTimeOffset.
  • Summary. Holds summary text for the story, which should be checked in conjunction with the Content property. This may include formatted text so is returned as a TextSyndicationContent object.
  • Title. The title of the item, as a TextSyndicationContent value.
30 June 2011