Quick success with XmlSerialization and RSS
I have been tinkering with adding an RSS feed on the EvanAndAbby.com site the past few “free times” I had available. After very little time I can say that the site is fully setup for syndication. I have implemented the 2.0 RSS specification after completing 8 simple steps.
- Grabbed a sample RSS 2.0 Xml file
- Created the XSD scheme using the above Xml sample file. Saved the results locally as my rss2.xsd file.
- Generated the System.Xml.Serialization class by running the following command:
- xsd -c -l:c# -n:Your.Namespace.Here "C:\PathToXsdFile\RSS2.xsd" /out:"C:\Temp"
- Added the generated class to my project
- Created the rss aspx page that will return “text/xml” as its Response.ContentType
- Instantiate the Rss and RssChannel objects from the generated class and fill the needed properties.
- Built the RssChannelItems. In my case I had a DataTable I could loop through.
- Lastly, Serialized the Rss object to a string that is sent in the response.
Bonus Step:
Validated the feed to ensure I was correctly following the specification.
That’s it!! With the help of some generation tools and the System.Xml assembly implementing this was very painless. XmlSerialization rules!
0 Comments:
Post a Comment
<< Home