Go to content Go to navigation Go to search

Brokenwire.NET::Programming

silverlight rss feed displayer
· May 22, 11:30 PM by Thijs Kroesbergen

Tonight I built a small silverlight application which reads this site’s rss feed and displays it in a “nice” format.

See SilveRSS in action!

Getting the animation done was quite simple too, but I did some fine-tuning inside the XAML code myself. Probably because I don’t know Expression Blend well enough yet.

The biggest challenge was to have the Silverlight applet decypher the rss-xml layout. But actually all that is very basic .NET programming.
The code to retrieve the rss data and parse the XML looks like this:

    Uri uri = new System.Uri("http://www.brokenwire.net/bw/rss");
    BrowserHttpWebRequest request = new BrowserHttpWebRequest(uri);
    HttpWebResponse response = request.GetResponse();
    StreamReader responseReader = new StreamReader(response.GetResponseStream());
    string rawvalue = responseReader.ReadToEnd();
    XmlReader xr = XmlReader.Create(new StringReader(rawvalue));
    while (xr.ReadToFollowing("item"))
    {
         //RssItem is a struct to contain the data for one item
         RssItem item;
         xr.ReadToFollowing("title");
         item.title = xr.ReadElementContentAsString();
         xr.ReadToFollowing("description");
         item.description = Strip(xr.ReadElementContentAsString());
         xr.ReadToFollowing("link");
         item.link = xr.ReadElementContentAsString();
         // Add items to a list
         _rssItems.Add(item);
    }

Controlling the animations is just a matter of catching the Storyboard “Completed” events.

Other examples I found on the web are using the power of the webserver to create XAML code on the server, and displaying that on the client. But I didn’t want to and didn’t need to write any server-side code in this example.

- Permalink -

  1. What namespace is Strip in or is it something your rolled yourself?

    Thanks for the example :)


    Glen    Sep 7, 05:20 PM    #
  2. Strip() is a home-made function, simply drops all HTML tags from a piece of text…


    — thijs    Sep 14, 10:05 PM    #
  3. can you email me all the source code to try out locally… thanks


    m lees    Oct 17, 02:32 PM    #
Name
E-mail
http://
Message
  Textile Help