The SyndicationFeed class from System.ServiceModel.Syndicatation makes it easy to work with feeds and extensions. The code below uses an RSS feed from space.live.com to show photo albums on a page. Of course there are many ways to consume RSS with and w/o code, but the WCF enhancements with .NET 3.5 are a nice new trick. You can see the result at http://www.steveres.com/SpacesPics.aspx
r = XmlReader.Create("http://yournamegoeshere.spaces.live.com/photos/feed.rss");albums = SyndicationFeed.Load(r);r.Close();foreach (SyndicationItem album in albums.Items){ // album.links[0].URI points to this album page on spaces.live.com// album.Summary (not shown) is an HTML block with thumbnails of the album picscell.Text= string.Format("<a href='{0}'>{1}</a>", album.Links[0].Uri, album.Title.Text);albumRSS = GetAlbumRSS(album);r = XmlReader.Create(albumRSS);photos = SyndicationFeed.Load(r);r.Close();foreach (SyndicationItem photo in photos.Items){// photo.Summary is an HTML block with a thumbnail of the pic cell.Text = string.Format("{0}", photo.Summary.Text);} }//// helper to extract the feed to one album from the albums feed//private string GetAlbumRSS(SyndicationItem album){ string url = "";foreach (SyndicationElementExtension ext in album.ElementExtensions) if (ext.OuterName == "itemRSS") url = ext.GetObject<string>();return (url); }
r = XmlReader.Create("http://yournamegoeshere.spaces.live.com/photos/feed.rss");albums = SyndicationFeed.Load(r);r.Close();foreach (SyndicationItem album in albums.Items){
// album.links[0].URI points to this album page on spaces.live.com// album.Summary (not shown) is an HTML block with thumbnails of the album picscell.Text= string.Format("<a href='{0}'>{1}</a>", album.Links[0].Uri, album.Title.Text);albumRSS = GetAlbumRSS(album);r = XmlReader.Create(albumRSS);photos = SyndicationFeed.Load(r);r.Close();foreach (SyndicationItem photo in photos.Items){// photo.Summary is an HTML block with a thumbnail of the pic cell.Text = string.Format("{0}", photo.Summary.Text);}
}//// helper to extract the feed to one album from the albums feed//private string GetAlbumRSS(SyndicationItem album){
string url = "";foreach (SyndicationElementExtension ext in album.ElementExtensions) if (ext.OuterName == "itemRSS") url = ext.GetObject<string>();return (url);
}