Geeks With Blogs


Timmy Kokke's Blog

↑ Grab this Headline Animator

Timmy Kokke at Blogged
Timmy Kokke …just sorting my bubbles…

silverbulletI’d like to provide you with a SilverBullet™, a small snippet of Silverlight, a class or namespace hidden in the silverlight .NET framework, to help you out in times of need. It’s not to learn, but something to keep in your pocket. Just remember it’s there and you’re safe.

Occasionally it’s required to use an Rss or an Atom feed in your projects. Just to show some news, or the latest update on the stock exchange. Working with these, often large, chucks of xml directly can be a pain. In Silverlight 3 (and .NET 3.5 and 4)  the System.ServiceModel.Syndication.SyndicationFeed class has been added. This class makes the processing of the feed a lot easier.

Say you have an service getting an Atom feed from somewhere and returning this as a string (how to do this can be found in an earlier tutorial I wrote about .Net Ria Services and Rss). Basically you’ll end up with a large string containing xml which represents an Atom or Rss feed. For the creation of a new SyndicationFeed you can use its static Load() method. This method takes an XmlReader object as a parameter, which is created using a StringReader, which takes a string. Got that? Here’s the code to clarify:

using(var reader = XmlReader.Create(new StringReader(AnXmlString)))
  var feed = SyndicationFeed.Load(reader);  
  // do something useful with the feed


To use this feed in your xaml, you can data-bind to properties like Title, Description and Copyright. The SyndicationFeed class also has a property which gets or sets a list of Items, a list of Authors and a list of Categories.

A lot of these properties use types which can be found in System.ServiceModel.Syndication also, to provide an easy use of the building block of the feeds, Classes like SyndicationItem, SyndicationPerson and TextSyndicationContent.

Another thing that’s worth mentioning, the SyndicationFeed class can also be used the other way around, to create feeds. After filling all the necessary properties, you can call the SaveAsAtom10 or SaveAsRss20 methods to write the output using a XmlWriter.


Last, have a look here for bit of source code to play with.


Shout it
Tags van Technorati:
dotNed blogger
kick it on
Posted on Tuesday, September 29, 2009 11:14 PM Silverlight , SilverBullet , dotnetmag , CodeProject | Back to top

Comments on this post: SilverBullet #11 - SyndicationFeed

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Timmy Kokke | Powered by: