Syndication Extensibility

The Syndication API is designed to provide a format-neutral programming model that allows syndicated content to be written to the wire in a variety of formats. The abstract data model consists of the following classes:

These classes map closely to the constructs defined in the Atom 1.0 specification, although some of the names are different.

A key feature of syndication protocols is extensibility. Both Atom 1.0 and RSS 2.0, add attributes and elements to syndication feeds that are not defined in the specifications. The Windows Communication Foundation (WCF) syndication programming model provides the following ways of working with custom attributes and extensions, loosely-typed access and deriving a new class.

Loosely Typed Access

Adding extensions by deriving a new class requires writing additional code. Another option is accessing extensions in a loosely-typed way. All of the types defined in the syndication abstract data model contain properties named AttributeExtensions and ElementExtensions (with one exception, SyndicationContent has an AttributeExtensions property but no ElementExtensions property). These properties are collections of extensions not processed by the TryParseAttribute and TryParseElement methods respectively. You can access these unprocessed extensions by calling System.ServiceModel.Syndication.SyndicationElementExtensionCollection.ReadElementExtensions.String,System.String) on the ElementExtensions property of SyndicationFeed, SyndicationItem, SyndicationLink, SyndicationPerson, and SyndicationCategory. This set of methods finds all extensions with the specified name and namespace, deserializes them individually into instances of TExtension and returns them as a collection of TExtension objects.

Deriving a New Class

You can derive a new class from any of the existing abstract data model classes. Do this when implementing an application in which most of the feeds you are working with have a particular extension. In this topic, most of the feeds that the program works with contain a MyExtension extension. To provide an improved programming experience, do the following steps:

  • Create a class to hold the extension data. In this case, create a class called MyExtension.

  • Derive a class called MyExtensionItem from SyndicationItem to expose a property of type MyExtension for programmability purposes.

  • Override TryParseElement in the MyExtensionItem class to instantiate a new MyExtension instance when a MyExtension is read in.

  • Override WriteElementExtensions in the MyExtensionItem class to write the contents of the MyExtension property to an XML writer.

  • Derive a class called MyExtensionFeed from SyndicationFeed.

  • Override CreateItem in the MyExtensionFeed class to instantiate a MyExtensionItem instead of the default SyndicationItem. A series of methods are defined in SyndicationFeed and SyndicationItem that can create SyndicationLink, SyndicationCategory, and SyndicationPerson objects (for example, CreateLink, CreateCategory, and CreatePerson). All of which can be overridden to create a custom derived class.

See Also

Concepts

WCF Syndication Overview
Architecture of Syndication