Atom to RSS 2.0 converter – The C# way

This blog was on blogger but a few weeks ago it started to launch a java connection exception. It doesn’t allowed me to publish my blog at this address through ftp.

Then I decided to switch to WordPress so I extracted a backup from blogger in the Atom format and tried to import it, but WordPress only accepts RSS 2.0

I tried to find an out of the box solution to make this convertion between Atom and RSS but nothing. So this is my implementation in C#

 1:// -----------------------------------------------------------------------
 2:// Isaias Gonzalez <siderevs@gmail.com>
 3:// -----------------------------------------------------------------------
 4:
 5:using System.IO;
 6:using System.ServiceModel.Syndication;
 7:using System.Xml;
 8:
 9:namespace DeAtomizer
10:{
11:    public class AtomToRss2Converter
12:    {
13:        public void AtomToRss20(string atomFileName, string rssFileName)
14:        {
15:            ConvertToRss20(ReadFeed(atomFileName), rssFileName);
16:        }
17:
18:        private static void ConvertToRss20(SyndicationFeed feed, string rssFileName)
19:        {
20:            Rss20FeedFormatter rss2 = new Rss20FeedFormatter(feed);
21:            XmlWriter writer = XmlWriter.Create(rssFileName);
22:            rss2.WriteTo(writer);
23:
24:            // You can also use 
25:            // feed.SaveAsRss20(writer);           
26:        }
27:
28:        private static SyndicationFeed ReadFeed(string fileName)
29:        {
30:            StreamReader stream = new StreamReader(fileName);
31:            XmlReader reader = XmlReader.Create(stream);
32:            SyndicationFeed feed = SyndicationFeed.Load(reader);
33:            return feed;
34:        }
35:    }
36:}

And as you can see, I successfully converted the file.

Posted on November 28, 2008 at 5:53 am by Isaias · Permalink
In: .Net, Software

2 Responses

Subscribe to comments via RSS

  1. Written by farneville
    on April 29, 2010 at 3:58 am
    Reply · Permalink

    Dude How can I convert it from online my blog is still on blogger and it got hacked and cannot be retrieved. Just wondering if you can make it pull data from the internet not from a saved file.

    Thanks,
    Farneville

    • Written by Isaias
      on April 29, 2010 at 9:30 am
      Reply · Permalink

      You can pull it from the internet but the content might depend on the settings. Is your feed configured to show the complete post or just a part? the feed contains all of the post or just the last 10?

Subscribe to comments via RSS

Leave a Reply