Recently I wanted to setup up an RSS feed reader and blog item display window on our website. In order to do something different (and because I'm inherently lazy), I thought it would be cool to use Microsoft's XSD.EXE tool to gen. the classes from an XML schema for RSS 2.0, write a bit of code around this and use it on our site. My primary interest was to consume the RSS feeds coming off various sites and use the blog channels I was interested in.
So, the tasks that needed doing were:
- Validate the feeds as RSS 2.0 conformant
I found a useful website at http://feedvalidator.org/ that allows you to submit RSS feed url's and reports on their conformance. Except for some minor issues, the feeds from today's modern blog sites are usually conformant (phew)! P>
- Find an XSD that works
This is an issue, as there appears to be more than one 'standard' for the RSS 2.0 XML format. After plugging many of these XSD's into XMLSpy and validating against the rss feeds, I found an XSD that worked and against which the stream can be validated. The XSD can be downloaded here: http://www.thearchitect.co.uk/schemas/rss-2_0.xsd.
- Generate the code classes and deserialize the RSS stream
Also an issue. XSD.EXE generates code incorrectly when a choice-item includes an enumerated type. The XmlChoiceIdentifierAttribute serialization attribute causes the reflection of the classes to fail! So what appeared to be the easy way to read RSS streams was becoming more difficult. This was resolved (and could easily be the subject of a meaty article). You can download my working code here. The cool thing about this code is that it should be very easy to generate RSS 2.0 conformant XML streams without much added code.
The working code contains both the original code-class file generated by XSD.EXE and the modified file (which works). The basis for these manual fixes can be found here:
Implementing XML Key Management Services Using ASP.NET ('The XKMS Object Model' section)
Watch this space - I intend getting our CodeXS code generator working correctly with this schema and producing a fully-fledged RSS 2.0 serializer....(soon-ish!)