use Html agility pack to download rss and show elements on a list

c# html-agility-pack rss windows-phone xml


I use html agility pack do download from my rss source, so far i can download it right and i can access all the elements with SelectNode but how can i lets say i have an title in my rss and it is one node in the item node, i can read it but how to list it on a listbox?!

i use this to download the rss

HtmlWeb.LoadAsync("", DownLoadCompleted);

void DownLoadCompleted(object sender, HtmlDocumentLoadCompleted e)
        if (e.Error == null)
            HtmlDocument doc = e.Document;
            if (doc != null)
                foreach (HtmlNode rsstitle1 in doc.DocumentNode.SelectNodes("//title")) 
                    var title = doc.DocumentNode.SelectNodes("//title");

                    if (rsstitle1 != null)
                            string titleText = rsstitle1.InnerText;
                            rsstitle.Text = titleText;

this "rsstitle" is an element on the mainpage an textBlock inside an listbox names "listBox1", i see the strig titleText in the textblock but i see only the last item, it seems like it circles all the way thru to the last title in the downloaded rss items list. so my question is how can i make an list of all titles. the xml from the rss look like this:

<?xml version='1.0' encoding='UTF-8'?>
<rss xmlns:atom='' xmlns:openSearch='' xmlns:blogger='' xmlns:georss='' xmlns:gd='' xmlns:thr='' version='2.0'>
    <lastBuildDate>Fri, 11 Oct 2013 13:24:41 +0000</lastBuildDate>
    <category>suma sumarum</category>
    <title>Windows Phone Novosti</title>
    <description>Prvi Windows Phone blog u Bosni i Hercegovini koji vama donosi sve potrebne informacije za vas omiljeni Windows Phone operativni sistem.</description>
    <managingEditor> (Dino Borogovac)</managingEditor>
      <guid isPermaLink='false'>,</guid>
      <pubDate>Fri, 11 Oct 2013 13:24:00 +0000</pubDate>
      <category domain=''>aplikacije</category>
      <title>Facebook Beta aplikacija sa novom nadogradnjom</title>
      <description>&lt;div align="justify"&gt;&lt;a href=""&gt;&lt;img alt="IMG_2353" border="0" height="447" src="" style="background-image: none; border: 0px currentcolor; display: block; float: none; margin: 0px auto;" title="IMG_2353" width="670" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div align="justify"&gt;Facebook Beta aplikacija dobila novu nadogradnju, ovo je jedna od rijetkih aplikacija koja se redovno aktualizira sa popravkama, novostima i novim funkcijama. Facebook Beta je aplikacija koja sluzi Microsoft-u za testiranje novih funkcija prije nego sto one izadu u oficijelnu aplikaciju �Facebook�.&lt;/div&gt;&lt;div align="justify"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;U novoj verziji, koja je za WP7 kao i za WP8 Microsoft-ovi razvijaci su napisali da su dodali jos par jezika (prevoda) u aplikaciju i popravili generalno brzinu aplikacije.&lt;/div&gt;&lt;a href=""&gt;&lt;br /&gt;&lt;table class="app-download" summary="Skinite aplikaciju iz ovog clanka"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;img height="160" src="" style="display: inline;" title="Facebook aplikacija" width="160" /&gt;&lt;/td&gt;&lt;td&gt;&lt;span style="font-size: x-large; font-weight: bold;"&gt;Facebook Beta&lt;/span&gt;&lt;br /&gt;od: Microsoft Corp.&lt;br /&gt;Verzija:;br /&gt;Cijena: Besplatno&lt;br /&gt;&lt;br /&gt;&lt;img src="" /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/a&gt;</description>
      <author> (Dino Borogovac)</author>
      <media:thumbnail xmlns:media='' url='' height='72' width='72'/>

There are another 25 elements wit hall the same inside like title, description, pubdate, and link. i would like to have:

First all the titles in one list in the mainpage.

Second all the links bind to the titles so if the users taps on it so it goes to my other page where is can pass the url to an webbrowser control.

Third if its possible to make an short description under the title

Fourth show the post body which is in the "description" element of the rss already downloaded, and leave the elements like they are on the rss because there are elements like pictures and tables and so on that i need.

Popular Answer

Rather than using Agility Pack (which you can use for sure), it is a good idea to use .NET provided classes which can help you to parse and manipulate RSS feeds. I believe, you want to build a RSS reader kind of application. There are lot of samples are following links should help you:

Hope this helps.

Let us know if this solves your problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why