Geeks With Blogs
Mark Pearl

 

Today I thought I would just list a little tutorial on how to make an RSS feed reader in C#. The code is very simple…

    public class RssFeedReader
    {
        public IEnumerable<Post> ReadFeed(string url)
        {
            var rssFeed = XDocument.Load(url);

            var posts = from item in rssFeed.Descendants("item")
            select new Post
            {
                Title = item.Element("title").Value,
                Description = item.Element("description").Value,
                PublishedDate = item.Element("pubDate").Value
            };

            return posts;
        }
    }

    public class Post
    {
        public string PublishedDate;
        public string Description;
        public string Title;
    }

An example of using this would be as follows…

    class Program
    {
        static void Main(string[] args)
        {
            var posts = new RssFeedReader().ReadFeed(@"http://www.pwop.com/feed.aspx?show=dotnetrocks&filetype=master");
            Console.WriteLine(posts.ToList().Count);
            Console.ReadLine();
        }
    }
Posted on Friday, December 2, 2011 6:38 AM C# | Back to top


Comments on this post: Linq to XML to make a RSS Feed Reader in C#

# re: Linq to XML to make a RSS Feed Reader in C#
Requesting Gravatar...
Man THANKS A LOT!

Your post is excelent, thank you for this, i am going to use this in my xamarin app. There is no WCF for starter edition and your solution is perfect!!

Keep up the good work !
Left by Vitaliy on Feb 25, 2015 2:45 PM

# re: Linq to XML to make a RSS Feed Reader in C#
Requesting Gravatar...
Thank you very much

It worked!
Left by Ajay on Feb 12, 2016 11:16 AM

# re: Linq to XML to make a RSS Feed Reader in C#
Requesting Gravatar...
this was exactly what I was looking for.
I had to get the XML values first but your class rock!
Left by This is great, on Dec 10, 2016 6:04 AM

Your comment:
 (will show your gravatar)


Copyright © MarkPearl | Powered by: GeeksWithBlogs.net