Home > Articles > Operating Systems, Server > Microsoft Windows Desktop

  • Print
  • + Share This
This chapter is from the book

Syndicated Content

Syndicated content is information that is available to other sites through special feeds. These feeds are most often presented in an XML format using either RSS (stands for RDF Site Summary, although it is commonly referred to as Real Simple Syndication—RDF is an abbreviation of Resource Description Framework) and Atom. Both formats have evolved as standard XML-based ways for blogs, websites, and other content providers to expose data in a consistent way so that other programs can download and consume the data.

The RSS specification is available online at http://www.rssboard.org/rss-specification.

The Atom publishing protocol is available online at http://atompub.org/.

Both formats provide a way to specify a feed, which is a set of related entries (topics, articles, or posts). Each entry may have a post date, information about the author, a set of links that reference the original source, and rich content such as images and videos. To parse the data in the past, you would either have to read the specifications and write your own special XML parser or find a third-party parser that would do it for you.

The Windows Runtime provides the SyndicationClient class to make it easy for you to interact with feeds. This class exists in the Windows.Web.Syndication namespace. The class can be used to asynchronously retrieve feed information and can be provided credentials to connect with sources that require authentication. When passed a URL, it is capable of parsing feeds in Atom (0.3 and 1.0) and RSS (0.91, 0.92, 1.0, and 2.0) format and presenting them using a common object model.

The sample program retrieves the feed just using four lines of code. Two lines are not required and are used to take advantage of the browser cache and provide a custom user agent to the host website when requesting the data. A helper method named GetSyndicationClient returns the client with some default properties set in the BlogDataSource class:

private static SyndicationClient GetSyndicationClient()
    var client = new SyndicationClient
                        { BypassCacheOnRetrieve = false };
    client.SetRequestHeader("user-agent", USER_AGENT);
    return client;

Using the client is as simple as calling a method to retrieve the feed by passing the location of the feed:

var client = GetSyndicationClient();
var feed = await client.RetrieveFeedAsync(group.RssUri);

The result of the operation, if successful, is a SyndicationFeed object. The instance contains information about the location of the feed, categories or tags hosted by the feed, contributors to the feed, links associated with the feed, and of course the items that are posted to the feed. Each SyndicationItem in the feed hosts the location of the item, categories or tags specific to that item, the title and content of the item, and an optional summary.

You can follow the code in the example to see how easy it is to parse the feed and retrieve the necessary data. There is no need for you to specify the format of the feed because the class will figure this out automatically from the feed itself. Syndication is a powerful way to expose content and consume it in Windows 8 applications.

  • + Share This
  • 🔖 Save To Your Account