Lessons learned using RSS with .NET 2.0: Simplicity and Speed

RSS, .NET 2.0, and Interop

For many people, when they think of Interop with respect to .NET development, they think, first and foremost, Web Services. This is good as far as it goes but...Web services is neither necessary nor sufficient for interop in many cases. RSS is a great example of an XML document protocol that is very useful for interop - in practice, interop between RSS Readers, RSS producers, aggregators, and so on. The document format is RSS, the protocol over which that document is exchanged is often HTTP - the web protocol - but of course it could be *anything*. Any protocol. How does .NET 2.0 support RSS for Interop?

A Digression - IE7 and RSS

I installed IE7 a while back, and I am pretty happy about the RSS support built-in to it. Navigate to an RSS feed and you get a reasonable user-friendly display of the feed. It's not a feed reader or rss manager, but it's nice to not see the angle brackets in the browser, when I just want to browse an RSS doc.

RSS Example

Separately, I wanted an app that could dynamically create a digest of a website - this is a sort of tactical app I needed for something at work. Obviously, it's gotta be RSS or ATOM. I wanted build the app in .NET, and it will run as a web app. This means ASP.NET.

How can I create an RSS doc from within .NET? I know about the RSS.NET project on sourceforge, and I have actually used that DLL in some other projects - RSS.NET was integrated into the Club Web Starter Kit that was created as a usable example of what you could do with ASP.NET 2.0. It was good for what it did, but I had a few problems (this was a while ago) with particular variants of RSS. I made some changes but never bothered to raise a bug on the sourceforce project, basically it was more effort than I was signed up for. In any case it worked, but I was a bit shy of the license, and so on.

Now I Was doing some more RSS stuff, and with my bad developer habits , I ignored what already existed and set off to build my own RSS library. After much effort, many errors, and... oh, wait. Hold on a second. It wasn't much effort after all, and there were no errors and backtracking. Basically it took me 10 minutes to build an RSS library in .NET, and it was very straightforward. Here's the resulting class diagram from Visual Studio 2005:

RSSModel Class Diagram

The process was pretty simple and the same approach should work with any XML dialect. How did I do it?

The tools in the .NET SDK make this simple

The first thing I did was grab a sample RSS document. Then I ran it through the xsd.exe tool, which is part of the .NET 2.0 SDK. The result of that was an XSD document, describing the schema for RSS. Then I ran that through xsd.exe , and the output of that was a .cs source file, modelling the RSS document.

Aside: Lots of developers have this idea that the output of a tool, any tool, is sacrosanct, and cannot be changed. As if the tool knows better than you, what you need. I don't subscribe to that philosophy. The output of one tool is just the input to the next tool, in my opinion.

I took the .cs source file that was kindly generated for me by xsd.exe, and doctored it up, added a few helper methods to the generated classes, tweaked the names of the classes and so on, and I had myself a simple RSS library, perfectly suited to my purposes. (Note: the diagram above is from Visual Studio. It essentially is a graphcial model of the generated class. I didn't actually use any premium feature in Visual Studio to generate the class. I used only the .NET SDK Tools. VS just generated the pretty picture.)

Honestly** , the entire effort on this was about 10 minutes. As I prototyped the app, I saw what I needed and what was missing from the RSS object model, and I tweaked it a little as I went along. A few iterations and the project was done. Boom. I didn't need to examine the license for a third-party tool, I didn't need to understand the model for the third party code. It was small and simple (Really Simple, you might say!). If you want to see the source, see the link below.

[**Honestly, don't you hate when people say, "Honestly,..." As if most of the time they're not being honest, but this time they really are....]

That's what I love about .NET development: Things are surprisingly easy to accomplish. This approach should work with any XML dialect. I am sure there are billions and billions out there, and most of them, if they are simple enough, should be workable with this approach.

What I did here was generate a library that allows any .NET application to produce an RSS document from any content type it can access. I could also have extended this so that it could consume RSS streams, but that was out of scope for my project, so I didn't do it. You should be able to do something similar for any XML Schema, including internal-only schema that you use only for exchanging documents inside the walls of your corporation or organization.

Happy angle brackets to you!

RssModel.cs