LINQ to HTML/XML C#
-
Hi all, I have come to problem, which i am unable to find a solution... I need to parse a RSS document (containing as always some XML and some HTML) using LINQ The document is web response from yahoo weather feeds, given below.
<rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84\_pos#">
<channel><title>Yahoo! Weather - Islamabad, PK</title>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Islamabad\_\_PK/\*http://weather.yahoo.com/forecast/PKXX0006\_c.html</link>
<description>Yahoo! Weather for Islamabad, PK</description>
<language>en-us</language>
<lastBuildDate>Mon, 15 Feb 2010 6:55 am PKT</lastBuildDate>
<ttl>60</ttl>
<yweather:location city="Islamabad" region="" country="Pakistan"/>
<yweather:units temperature="C" distance="km" pressure="mb" speed="km/h"/>
<yweather:wind chill="5" direction="50" speed="19.31" />
<yweather:atmosphere humidity="76" visibility="4.01" pressure="982.05" rising="0" />
<yweather:astronomy sunrise="6:52 am" sunset="5:51 pm"/>
<image>
<title>Yahoo! Weather</title>
<width>142</width>
<height>18</height>
<link>http://weather.yahoo.com</link>
<url>http://l.yimg.com/a/i/us/nws/th/main\_142b.gif</url>
</image>
<item>
<title>Conditions for Islamabad, PK at 6:55 am PKT</title>
geo:lat33.71</geo:lat>
geo:long73.08</geo:long>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Islamabad\_\_PK/\*http://weather.yahoo.com/forecast/PKXX0006\_c.html</link>
<pubDate>Mon, 15 Feb 2010 6:55 am PKT</pubDate>
<yweather:condition text="Haze" code="21" temp="8" date="Mon, 15 Feb 2010 6:55 am PKT" />
<description><![CDATA[<img src="http://l.yimg.com/a/i/us/we/52/21.gif"/><br />
<b>Current Conditions:</b><br />
Haze, 8 C<BR />
<BR /><b>Forecast:</b><BR />
Mon - Rain. High: 14 Low: 4<br />
Tue - PM Showers. High: 17 Low: 6<br />
<br />
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/Islamabad\_\_PK/\*http://weather.yahoo.com/forecast/PKXX0006\_c.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
(provided by <a href="http://www.weather.com" >The Weather Channel</a> -
Hi all, I have come to problem, which i am unable to find a solution... I need to parse a RSS document (containing as always some XML and some HTML) using LINQ The document is web response from yahoo weather feeds, given below.
<rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84\_pos#">
<channel><title>Yahoo! Weather - Islamabad, PK</title>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Islamabad\_\_PK/\*http://weather.yahoo.com/forecast/PKXX0006\_c.html</link>
<description>Yahoo! Weather for Islamabad, PK</description>
<language>en-us</language>
<lastBuildDate>Mon, 15 Feb 2010 6:55 am PKT</lastBuildDate>
<ttl>60</ttl>
<yweather:location city="Islamabad" region="" country="Pakistan"/>
<yweather:units temperature="C" distance="km" pressure="mb" speed="km/h"/>
<yweather:wind chill="5" direction="50" speed="19.31" />
<yweather:atmosphere humidity="76" visibility="4.01" pressure="982.05" rising="0" />
<yweather:astronomy sunrise="6:52 am" sunset="5:51 pm"/>
<image>
<title>Yahoo! Weather</title>
<width>142</width>
<height>18</height>
<link>http://weather.yahoo.com</link>
<url>http://l.yimg.com/a/i/us/nws/th/main\_142b.gif</url>
</image>
<item>
<title>Conditions for Islamabad, PK at 6:55 am PKT</title>
geo:lat33.71</geo:lat>
geo:long73.08</geo:long>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Islamabad\_\_PK/\*http://weather.yahoo.com/forecast/PKXX0006\_c.html</link>
<pubDate>Mon, 15 Feb 2010 6:55 am PKT</pubDate>
<yweather:condition text="Haze" code="21" temp="8" date="Mon, 15 Feb 2010 6:55 am PKT" />
<description><![CDATA[<img src="http://l.yimg.com/a/i/us/we/52/21.gif"/><br />
<b>Current Conditions:</b><br />
Haze, 8 C<BR />
<BR /><b>Forecast:</b><BR />
Mon - Rain. High: 14 Low: 4<br />
Tue - PM Showers. High: 17 Low: 6<br />
<br />
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/Islamabad\_\_PK/\*http://weather.yahoo.com/forecast/PKXX0006\_c.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
(provided by <a href="http://www.weather.com" >The Weather Channel</a>I'm just stating the obvious but there is [EDIT] no [/EDit] XLINQ method to get "nodes" inside a XCDATA.Just the value/text wich is everything inside the XCData. You have to manually set up a routine to extract the needed data(s). Wich can be quite easy if all you ever need to get is the <img src="...".
modified on Tuesday, February 16, 2010 10:29 PM