I am working on a project for an RSS Client. Right now I’m retrieving a feed using SyndicationFeed and an XmlReader and adding it to a list:
SyndicationFeed feed = SyndicationFeed.Load(
XmlReader.Create("SOME URL TO A FEED"));
List<SyndicationFeed> feeds = new List<SyndicationFeed>();
feeds.Add(feed);
SyndicationFeed and most of its properties are not serializable. I need to be able to save the feeds and their respective items when my program is closed. I have a database solution working with Entity Framework but I would like to get away from this. So my next thought was to simply serialize the container with all the feeds but that’s no go. Should I write serializabl class that mimics the SyndicationFeed and its properties and do a sort of boxing and unboxing or is there a better way?
The
SyndicationFeedclass has aSaveAsAtom10method and aSaveAsRss20method, both of which take aXmlWriterinstance which you can use anything as the underlying store for.Personally, I’d go with the
SaveAsAtom10method, as I believe Atom is the richer format.That said, you can easily persist this into a larger single document by creating a root element and child element in your own namespace, and then having the contents of each feed as the child, like so:
I’d use an
XDocumentandXElementinstances to handle creating the container above, as namespace management is much easier when using those classes. Additionally, theXElementclass exposes aCreateWriterand aCreateReader, which will exposeXmlWriterandXmlReaderinstances respectively, which you can then pass to yourSaveAsAtom/SaveAsRss20methods.However, I’d impress upon you to store each of the items separately; depending on how many feeds you have, creating one massive super document might be too much of a drain on resources, depending on your needs. Single document instances persisted in individual entities which you can access independently would probably be much more efficient to process.
You can still use the
SaveAsAtom10and aSaveAsRss20methods to serialize the feeds.