tags:

views:

149

answers:

6

I'd like the user to specify a RSS feed address and serialize the information from it. I am not interested in the XML format, but populate a strongly typed object from the XML. My question is, is there a standard that all RSS feeds support (Do all of them have date, title etc)? If so, is there a XSD that describes this. If not, how do I handle serializing a RSS feed to an object in ASP.NET?

EDIT: The SyndicationFeed's Items have the following properties:

  • Title.Text -> Gives us the title
  • Summary.Text -> Gives the Summary

Q1 - The Summary includes the html tags. Is there a way to strip them? I am interested only in the text Q2 - Do all RSS feeds have full content in the Summary element? I see that some RSS feeds have only a few lines for Summary while others have the entire content of the post. Thanks

A: 

Yes RSS is a standard format.

If you search for "C# RSS Reader" you'll find lots of implementations of helper objects that get you the information from the feed.

You could instead just use Linq to XML to get at the information directly from the XML. Scott Guthrie shows you how in his blog his blog.

mattx
Please see edit. Thanks
DotnetDude
A: 

.NET Framework version 3.5 provides classes to read feeds. This article describes how to do it.

If you are not using 3.5, then you can try Atom.NET (Note: last updated 6 years ago).

Jesse C. Slicer
+1  A: 

Hi there, if you reference the System.ServiceModel.Web there are some options to fetch a feed into a strongly typed object

using (var reader = XmlReader.Create(@"http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml"))
{
    var feed = SyndicationFeed.Load(reader);
    if (feed != null)
    {
        foreach (var item in feed.Items)
        {
            Console.WriteLine(item.Title.Text);
        }
    }
}
Rohan West
@Rohan West - Please see edit
DotnetDude
A: 

The standard at the moment, W3C, is RSS 2.0. RSS 0.91, 0.92 and 2.0 respectively.

Using .Net RSS.Net has always come in handy.

subv3rsion
A: 

I can suggest you to take a look to Argotic framework. Really easy and usefull, bath for consume and produce RSS feeds.

tanathos
A: 

You can use the following function:

    public object getRSS(string url)
{
    XDocument feedXML = XDocument.Load(url);
    var feeds = from feed in feedXML.Descendants("item")
                select new
                {
                    Title = feed.Element("title").Value,
                    Link = feed.Element("link").Value,
                    Description = feed.Element("description").Value,
                };

    return feeds;
}
sherbeny