0

I want to read a specific line of a RSS feed to display the information in a Label using visual C#. Given below is the Rss feed.

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"><channel>
<title>Weather Underground</title>
    <link>http://www.wunderground.com/</link>
    <category>weather</category>
<item>
    <title>Current Conditions : 28C, Mostly Cloudy - 9:10 AM IST Jun. 28</title>
    <link>http://www.wunderground.com/global/stations/43466.html</link>
    <description><![CDATA[Temperature: 28&deg;C | Humidity: 79% | Pressure: 1011hPa            (Steady) | Conditions: Mostly Cloudy | Wind Direction: SW | Wind Speed: 15km/h<img src="http://server.as5000.com/AS5000/adserver/image?ID=WUND-00071&C=0" width="0" height="0"  border="0"/>]]>
    </description>
    <pubDate>Thu, 28 Jun 2012 09:10:00 IST</pubDate>
</item>

<item>
    <title>Forecast for Wednesday Night as of Jun. 27 5:30 PM IST</title>
    <link>http://www.wunderground.com/global/stations/43466.html</link>    
    <description>
    Chance of a Thunderstorm. Low:26 &amp;deg; C.
     </description>
     <pubDate>Wed, 27 Jun 2012 12:00:00 GMT</pubDate>
     <guid isPermaLink="false">1340798400-1-night</guid>
  </item>

  <item>
      <title>Forecast for Thursday as of Jun. 27 5:30 PM IST</title>
       <link>http://www.wunderground.com/global/stations/43466.html</link>
       <description>
        Chance of a Thunderstorm. High:31 &amp;deg; C.//This is the line that I need
      </description>
      <pubDate>Wed, 27 Jun 2012 12:00:00 GMT</pubDate>
      <guid isPermaLink="false">1340884800-2-day</guid>
   </item>

There are many Item tags in this XML file how do I refer to the one that i need and get the text inside that description tag?

Sindu_
  • 1,347
  • 8
  • 27
  • 67

1 Answers1

1

you may do something like this read all the description to a list and then get specific description from a list

    var rss = XDocument.Load("your rss file");
    var items = (from c in rss.Descendants("item") select new{
                 Title  = (string)c.Element("description")      
                }).ToList();

// first description 

    string firstitem= items[0].Title.ToString();
BenMorel
  • 34,448
  • 50
  • 182
  • 322
COLD TOLD
  • 13,513
  • 3
  • 35
  • 52
  • When I do this: var rss = XDocument.Load("your rss file"); It says cannot assign void to an implicitly typed local variable. – Sindu_ Jun 28 '12 at 05:04
  • try this XDocument rss = XDocument.Load("your rss file"); – COLD TOLD Jun 28 '12 at 05:29
  • Thanks. I have included the wrong important statement now that's okay. But there's another thing it says the name 'item' does not exist in the current context: Title = (string)item.Element("description") – Sindu_ Jun 28 '12 at 06:15