posts - 280, comments - 318, trackbacks - 0

My Links

News

View Steve Michelotti's profile on LinkedIn

Twitter












Tag Cloud

Archives

Post Categories

Blend Bloggers

Bloggers that I follow

Books

F# Bloggers

F# Communities

F# Online Books

Fonts

HTML CSS ASP

Machine Learning

My Links

My Local UserGroups

My Online Presence

MY SA Links

Online Seminars

SA Software Companies

Web Design

Linq to XML to make a RSS Feed Reader in C#

 

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();
        }
    }

Print | posted on Friday, December 02, 2011 6:38 AM | Filed Under [ C# ]

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: