.NET, Archive, C#, Software Design

Parsing RSS From C#

I set out to write a RSS parser in C#. I know that several existing libraries are available for .NET that parse RSS streams, but out of curiosity I wanted to give it a go anyway.
Before I get started, for those interested in RSS libraries for .NET checkout RSS.NET or RSSConnect, to just name two.

As .NET developers we have some really powerful tools available to us that are built directly into the .NET framework. Take, for example, Serialization. In .NET we can turn an object into an XML resource using the XmlSerializer class, provided that the class is Serializable. In fact, the XmlSerializer object will even attempt to populate an object from an XML resource.

Visual Studio ships with a tool called XSD which can turn an XML Schema Definition into a C# class. Knowing that RSS is expressed as an XML resource, I set out to find an XSD for RSS. After some searching I found this site, which contains an XSD for RSS that the site’s author wrote. For posterity I have placed a mirror of that file on my own site, which you can find here.

Before continuing on, I need to pause and look ahead. The XSD that I found did not work out of the box, and I had to make a small modification to get it to work. I removed a reference to the RSS schema namespace from the XSD. The modified XSD can be downloaded from here

Now, armed with an XSD, we can have the XSD program make some classes for us. From a command prompt (preferable the “Visual Studio Command Prompt” command prompt) type:

xsd RSS20.xsd /classes

Provided that RSS20.xsd is the name of the RSS XSD, and that you are currently in the same directory as RSS20.xsd, the XSD program should output a single file called RSS20.cs. The C# source file that XSD produced contains a class definition for each RSS entity, most notable the root node called “rss”.

With classes that represent RSS, we can now use the XmlSerializer object to easily populate an object with RSS data. For example:

     string rssXml = "... your rss data here ...";
XmlSerializer helper = new XmlSerializer(typeof(rss));
rss obj = (rss)helper.Deserialize(new StringReader(rssXml));

The above code snippet, will create an rss instance called “obj” from raw RSS data. But, you don’t want to have to do this everytime you want to parse RSS. Instead, it would be helpful if that logic was encapsulated by the rss object. Fortunately, the classes produced by the XSD program are all partial classes. So, in a separate .cs file, we can re-declare the rss class and expand upon its functionality.

//declare another portion of the "rss" object.
public partial class rss{
//add more methods to "rss" here
}
read more

.NET, Archive, ASP.NET, Javascript, Visual Studio

Visual Studio 2005 and .NET 3.5 Don’t Play Well Together

As many of you have, I also have experimented with the pre-releases of .NET 3.5 and Visual Studio codenamed Orcas. I, for better or worse, installed this pre-release software on my primary development machine which has Visual Studio 2005.

Despite having .NET 3.5 installed on my machine, my primary development occurred in .NET 2.0 via Visual Studio 2005. I had not experienced any problems with this setup until the other day. While attempting to build and publish an ASP.NET 2.0 website with AJAX extensions, I ran into a cryptic server error when executing the site on a staging server. The error was:

Could not load file or assembly 'System.Web.Extensions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 
or one of its dependencies. The system cannot find the file specified.

The System.Web.Extensions assembly is the ASP.NET AJAX assembly, so at first I simply thought that the staging server did not have AJAX extensions installed. After installing the AJAX extensions, the issue remained unresolved. A quick look in the machine’s GAC showed that it had version 1.0.61025.0, which is the latest version. Inspection of my development machine’s GAC showed both 1.0.61025.0 and 2.0.0.0 installed.

At this point I was puzzled how my machine had an unofficial version of AJAX extensions, and how my website was referencing it. Next I looked at the web.config of my site to see if I could just change the referenced version to 1.0. However, inspection of the web.config reveled:


<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
</add>

read more

.NET, Archive, ASP.NET, aspNETserve, C#

An Embedded ASP.NET Web Server

To correspond with the release of aspNETserve version 1.1, I have written a simple demonstration of hosting an ASP.NET 2.0 web server right into your own application.

The following code sample is about as simple as it gets.

using System; using System.Collections.Generic; using System.Text; using aspNETserve; namespace ConsoleWebServer { class Program { static void Main(string[] args) { string physicalPath = "c:\\wwwroot"; int port = 8080; using (Server s = new Server(new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 }), "/", physicalPath, port)) { s.Start(); Console.WriteLine("Press any key to stop the server"); Console.ReadKey(); s.Stop(); } } } } read more

Archive

SVN Bridge For CodePlex

Just today CodePlex released a bridge to allow subversion access to CodePlex. SvnBridge works by running locally on your box, and emulating a subversion server. The SvnBridge turns around and translates those calls into calls to the TFS server that CodePlex runs. read more

Archive, ASP.NET, aspNETserve

aspNETserve Version 1.0

Just today version 1.0 of aspNETserve was released. This version fixes all known major bugs, and represents a feature complete version in regards to aspNETserve’s original goals. Specifically this means that it can host any ASP.NET 2.0 web application without the need for Internet Information Services (IIS). read more

Archive, ASP.NET, aspNETserve

aspNETserve beta 2

The second beta of aspNETserve has just been released. Among other improvements, this version includes an automated installer to allow for easy installation.

aspNETserve

I have only tested this on my personal machine, running Windows Vista. It should work on XP, and possibly 2000, but I have not had a chance to test those systems yet. read more

.NET, Archive, C#

Tail Recursion Revisited

A year ago I blogged about Tail Recursion in C# on .NET 2.0. With the public beta of .NET 3.5 now available, I decided to retry my little experiment.

For the experiment I used Beta 1 of .NET 3.5 (version 3.5.20404), which you can get from here. Using the supplied compiler, I compiled the following C# code:

public class TailTest{ public static void Main(){ TailTest f = new TailTest(); f.DoTail(0); } public void DoTail(int n){ int v = n + 1; System.Console.WriteLine(v); DoTail(v); } } read more