Syndicated Content
Syndicated content is information that is available to other sites through special feeds. These feeds are most often present in an XML format using either RSS (stands for RDF Site Summary, though 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.
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 4 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. This is the code from the BlogDataSource class:
var client = new SyndicationClient(); client.BypassCacheOnRetrieve = false; client.SetRequestHeader("user-agent", USER_AGENT); 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.