Reading XML element & child nodes using LINQ in Vb.net- help me in where condition :(

Posted by New Linq Baby on Stack Overflow See other posts from Stack Overflow or by New Linq Baby
Published on 2009-08-26T01:09:54Z Indexed on 2010/05/18 1:10 UTC
Read the original article Hit count: 634

Filed under:
|
|

Hi, I am new in LINQ world. I need an urgent help in reading the xml elements using LINQ with specific where condition.

I need to find the max air_temp for a county i.e where county name = "Boone" and hour id = "06/03/2009 09:00CDT"

i tried something like below, but no luck :

 Dim custs As IEnumerable = From c In Element.Load("C:\meridian.xml").Elements("county") _
                            Select c.Elements("hour").Elements("air_temp").Max()

 For Each x In custs
        Response.Write(custs(0).ToString())
 Next

------------------- here is the xml file :

 <forecasts>
      <issued>06/02/2009 12:00CDT</issued> 
    - <county name="Adair">
    - <hour id="06/02/2009 12:00CDT">
          <air_temp>61</air_temp> 
          <cloud_cover>overcast</cloud_cover> 
          <dew_point>59</dew_point> 
          <precip_prob>90</precip_prob> 
          <precip_rate>0.12</precip_rate> 
          <precip_type>rain</precip_type> 
          <snow_rate>0.0</snow_rate> 
          <wind_direction>NE</wind_direction> 
          <wind_speed>12</wind_speed> 
          <dew_point_confidence>-3/+3</dew_point_confidence> 
          <road_temp>64</road_temp> 
          <road_frost_prob>0</road_frost_prob> 
          <road_potential_evap_rate>429</road_potential_evap_rate> 
          <road_temp_confidence>-3/+2</road_temp_confidence> 
          <dew_point_confidence>-3/+3</dew_point_confidence> 
          <bridge_temp>63</bridge_temp> 
          <bridge_temp_confidence>-4/+2</bridge_temp_confidence> 
          <bridge_frost>NO</bridge_frost> 
      </hour>
    - <hour id="06/02/2009 13:00CDT">
          <air_temp>61</air_temp> 
          <cloud_cover>overcast</cloud_cover> 
          <dew_point>60</dew_point> 
          <precip_prob>70</precip_prob> 
          <precip_rate>0.01</precip_rate> 
          <precip_type>rain</precip_type> 
          <snow_rate>0.0</snow_rate> 
          <wind_direction>ENE</wind_direction> 
          <wind_speed>10</wind_speed> 
          <dew_point_confidence>-3/+3</dew_point_confidence> 
          <road_temp>65</road_temp> 
          <road_frost_prob>0</road_frost_prob> 
          <road_potential_evap_rate>411</road_potential_evap_rate> 
          <road_temp_confidence>-3/+2</road_temp_confidence> 
          <dew_point_confidence>-3/+3</dew_point_confidence> 
          <bridge_temp>64</bridge_temp> 
          <bridge_temp_confidence>-4/+1</bridge_temp_confidence> 
          <bridge_frost>NO</bridge_frost> 
      </hour>

© Stack Overflow or respective owner

Related posts about Xml

Related posts about LINQ