Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deserializing an RSS feed in .NET

Is it practical / possible to use serialization to read data from an RSS feed? I basically want to pull information from my Netflix queue (provided from an RSS feed), and I'm trying to decide if serialization is feasible / possible, or if I should just use something like XMLReader. Also, what would be the best way to download the feed from a URL? I've never pulled files from anything but drives, so I'm not sure how to go about doing that.

like image 678
MGSoto Avatar asked Aug 29 '09 01:08

MGSoto


1 Answers

If you can use LINQ, LINQ to XML is an easy way to get at the basics of an RSS feed document.

This is from something I wrote to select out a collection of anonymous types from my blog's RSS feed, for example:

protected void Page_Load(object sender, EventArgs e)
{
  XDocument feedXML = XDocument.Load("http://feeds.encosia.com/Encosia");

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

  PostList.DataSource = feeds;
  PostList.DataBind();
}

You should be able to use something very similar against your Netflix feed.

like image 55
Dave Ward Avatar answered Sep 27 '22 22:09

Dave Ward