De-serializing RSS XML

In our project at work we had a need for an RSS reader in c# and, through the power of Google, I managed to find quite a neat way of deserializing the RSS XML.

Basically all I needed to do, was save an example feed to a file on my hard disk. Then, using the Visual Studio Command Prompt and then run the command:

>xsd rss.xml

which generated several xsd files. Then I ran:

>xsd /c rss.xsd rss_app1.xsd rss_app2.xsd rss_app3.xsd

which generated the required c# class file (If you don’t add the other files, you may get the message “Error: Error generating classes for schema ‘rss’”). After copying the class file into my project, I was able to de-serialize the stream by writing:

           Â
using (Stream stream = WebRequest.Create(url).GetResponse().GetResponseStream())
{
    StreamReader reader = new StreamReader(stream);
    //string response = reader.ReadToEnd();
    XmlSerializer serializer = new XmlSerializer(typeof(RDF));
    feed = (RDF) serializer.Deserialize(stream);
}

As a certain meerkat would say, simples!

Tags:

  1. No comments yet.
(will not be published)

SetPageWidth