Scott Van Vliet

Less Talk, More Rock

August 2006 - Posts

Updates: WPF Book, Capgemini, London and Mumbai

It has been some time since I've posted on this blog (apart from my entry from earlier today, of course,) and it is with good reason – I've been busy!  So many things happened over the past couple months, so I thought it'd be good to catch up :)

Back in June, and after a few cycles with an relentless executive recruiter, I accepted an Senior Manager position within Capgemini’s Media & Entertainment practice.  In this role, I’ll be (and have been) leading up Architecture and Development for projects across the globe.  It’s a very exciting, challenging opportunity, and has thus far been quite fruitful.  It has also given me the opportunity to work on worldwide engagements – already seeing me in London, and off to Mumbai next week.

I wish that I had some good pictures from London, but I was so busy working that I didn’t have time to do much sightseeing!  Thus, enjoy this picture of Picadilly Circus, one of the few iconic landmarks I was able to see.

Picadilly Circus

Posted: Aug 29 2006, 10:22 PM by skillet | with 1 comment(s)
Filed under:
RSS in .NET Made Easy with XML Serialization

Based on my previous rants, here’s a stereotype for this post:

<<Casual_English_Used>>

So I was looking for a real quick way to publish an RSS feed from a Web application I created for a friend and found some great articles and components (RSS Toolkit for ASP.NET 2.0.)  However, I didn’t find anything that used XML Serialization (specifically) to work with the RSS 2.0 Specification (maybe my Google skills are truly weak today.)  I use XmlSerializer religiously, and thought it would be quite trivial to build a set of classes to quickly create and publish an RSS feed.   Thus, as any geek would do, I did just that.

Take a gander at the following model:

 RSS Object Model

These classes are adorned with System.Xml.Serialization attributes, which comply with the RSS 2.0 Specification.   To create an RSS document, it’s no more difficult than creating and populating a PONO (Plain Ole .NET Object.)

RssDocument rss = new RssDocument();

rss.Channel.Title = "My Feed";

rss.Channel.Link = "http://www.example.com/";

rss.Channel.Description = "A very cool feed on fun stuff.";

 

rss.Channel.Items.Add(new RssChannelItem());

rss.Channel.Items[0].Title = "Post #1";

rss.Channel.Items[0].Link = "http://www.example.com/content/post1.html";

rss.Channel.Items[0].Description = "The details for Post #1...";

rss.Channel.Items[0].Guid = "00000000-0000-0000-0000-000000000000";

To generate the XML for this feed, simply call the ToString() method:

rss.ToString();

It’s that simple!  Who’d have thought it’d be this easy :)  What’s more, I created a method to fetch an RSS feed and deserialize it into an instance of RssDocument (listed below.)

/// <summary>

/// Creates an RssDocument instance based on the RSS feed at

/// the specified URI.

/// </summary>

/// <param name="uri">The URI of the RSS feed to be loaded.</param>

/// <returns>

/// An instance of RssDocument based on the RSS feed

/// at the specified URI.

/// </returns>

public static RssDocument GetFeed(string uri)

{

    RssDocument feedDocument = null;

    WebClient client = null;

    byte[] feedData = null;

    MemoryStream ms = null;

    XmlSerializer xs = null;

 

    try

    {

        client = new WebClient();

        feedData = client.DownloadData(uri);

 

        ms = new MemoryStream(feedData);

        xs = new XmlSerializer(typeof(RssDocument));

        feedDocument = xs.Deserialize(ms) as RssDocument;

    }

    catch (Exception ex)

    {

        //

        // TODO: Handle Exception.

        //

        throw;

    }

    finally

    {

        ms.Close();

        ms.Dispose();

 

        client.Dispose();

    }

 

    return feedDocument;

} 

It’s not bulletproof, but gets the job done rather elegantly.  If you’d like a copy, grab it from the link below.

http://www.scottvanvliet.com/downloads/Boardworks.Rss.zip

Enjoy!

Posted: Aug 29 2006, 06:12 PM by skillet | with 14 comment(s)
Filed under: , ,
More Posts