tags:

views:

64

answers:

1

Below query works fine for me until I apply Where condition for Hour with attribute Id = '06/02/2009 12:00CDT'.

I need to get the max temp for today's date only, and I am not able to use the Where condition in the date field. Any ideas on what I am doing wrong?

Dim document = XDocument.Load("c:\meridian.xml") 
Dim wind_gusts = From county In document.Root.Elements("county") Where county.Attribute("name") = "Adams" _
From hour In county.Elements("hour") Where county.Element("hour").Attribute("id").Value = "06/02/2009 13:00CDT" _ 
From wind_gust In hour.Elements("wind_gust") _ 
Select CInt(wind_gust) '< DateTime.Parse("06/03/2009") _ 
'DateTime.Parse(county.Element("hour" + ID).Attribute("id")) 
'Dim wind_gust_value = wind_gusts.Max()

For Each m In wind_gusts
    Response.Write(m.ToString())
Next

Below is the xml :

 <?xml version="1.0" ?> 
- <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>
+ <hour id="06/02/2009 14:00CDT">
  <air_temp>64</air_temp> 
  <cloud_cover>overcast</cloud_cover> 
  <dew_point>60</dew_point> 
  <precip_prob>60</precip_prob> 
  <precip_rate>trace</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>65</road_temp> 
  <road_frost_prob>0</road_frost_prob> 
  <road_potential_evap_rate>560</road_potential_evap_rate> 
  <road_temp_confidence>-3/+2</road_temp_confidence> 
  <dew_point_confidence>-3/+3</dew_point_confidence> 
  <bridge_temp>65</bridge_temp> 
  <bridge_temp_confidence>-3/+2</bridge_temp_confidence> 
  <bridge_frost>NO</bridge_frost> 
  </hour>
+ <hour id="06/02/2009 15:00CDT">
  <air_temp>63</air_temp> 
  <cloud_cover>overcast</cloud_cover> 
  <dew_point>59</dew_point> 
  <precip_prob>50</precip_prob> 
  <precip_rate>trace</precip_rate> 
  <precip_type>rain</precip_type> 
  <snow_rate>0.0</snow_rate> 
  <wind_direction>NE</wind_direction> 
  <wind_gust>15</wind_gust> 
  <wind_speed>12</wind_speed> 
  <dew_point_confidence>-3/+3</dew_point_confidence> 
  <road_temp>63</road_temp> 
  <road_frost_prob>0</road_frost_prob> 
  <road_potential_evap_rate>397</road_potential_evap_rate> 
  <road_temp_confidence>-4/+3</road_temp_confidence> 
  <dew_point_confidence>-3/+3</dew_point_confidence> 
  <bridge_temp>63</bridge_temp> 
  <bridge_temp_confidence>-3/+2</bridge_temp_confidence> 
  <bridge_frost>NO</bridge_frost> 
  </hour>
+ <hour id="06/02/2009 16:00CDT">
  <air_temp>64</air_temp> 
  <cloud_cover>overcast</cloud_cover> 
  <dew_point>57</dew_point> 
  <precip_prob>40</precip_prob> 
  <precip_rate>trace</precip_rate> 
  <precip_type>rain</precip_type> 
  <snow_rate>0.0</snow_rate> 
  <wind_direction>ENE</wind_direction> 
  <wind_gust>16</wind_gust> 
  <wind_speed>11</wind_speed> 
  <dew_point_confidence>-3/+3</dew_point_confidence> 
  <road_temp>62</road_temp> 
  <road_frost_prob>0</road_frost_prob> 
  <road_potential_evap_rate>400</road_potential_evap_rate> 
  <road_temp_confidence>-3/+3</road_temp_confidence> 
  <dew_point_confidence>-3/+3</dew_point_confidence> 
  <bridge_temp>61</bridge_temp> 
  <bridge_temp_confidence>-4/+2</bridge_temp_confidence> 
  <bridge_frost>NO</bridge_frost> 
  </hour>
+ <hour id="06/02/2009 17:00CDT">
  <air_temp>63</air_temp> 
  <cloud_cover>overcast</cloud_cover> 
  <dew_point>56</dew_point> 
  <precip_prob>30</precip_prob> 
  <precip_rate>trace</precip_rate> 
  <precip_type>rain</precip_type> 
  <snow_rate>0.0</snow_rate> 
  <wind_direction>ENE</wind_direction> 
  <wind_gust>15</wind_gust> 
  <wind_speed>10</wind_speed> 
  <dew_point_confidence>-3/+3</dew_point_confidence> 
  <road_temp>61</road_temp> 
  <road_frost_prob>0</road_frost_prob> 
  <road_potential_evap_rate>344</road_potential_evap_rate> 
  <road_temp_confidence>-3/+3</road_temp_confidence> 
  <dew_point_confidence>-3/+3</dew_point_confidence> 
  <bridge_temp>60</bridge_temp> 
  <bridge_temp_confidence>-4/+2</bridge_temp_confidence> 
  <bridge_frost>NO</bridge_frost> 
  </hour>
+ <hour id="06/02/2009 18:00CDT">
  <air_temp>62</air_temp> 
  <cloud_cover>mostly cloudy</cloud_cover> 
  <dew_point>54</dew_point> 
  <precip_prob>20</precip_prob> 
  <precip_rate>trace</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/+4</dew_point_confidence> 
  <road_temp>61</road_temp> 
  <road_frost_prob>0</road_frost_prob> 
  <road_potential_evap_rate>530</road_potential_evap_rate> 
  <road_temp_confidence>-3/+3</road_temp_confidence> 
  <dew_point_confidence>-3/+4</dew_point_confidence> 
  <bridge_temp>61</bridge_temp> 
  <bridge_temp_confidence>-3/+2</bridge_temp_confidence> 
  <bridge_frost>NO</bridge_frost> 
  </hour>
+ <hour id="06/02/2009 19:00CDT">
  <air_temp>61</air_temp> 
  <cloud_cover>mostly cloudy</cloud_cover> 
  <dew_point>52</dew_point> 
  <precip_prob>10</precip_prob> 
  <precip_rate>trace</precip_rate> 
  <precip_type>rain</precip_type> 
  <snow_rate>0.0</snow_rate> 
  <wind_direction>ENE</wind_direction> 
  <wind_speed>7</wind_speed> 
  <dew_point_confidence>-3/+4</dew_point_confidence> 
  <road_temp>68</road_temp> 
  <road_frost_prob>0</road_frost_prob> 
  <road_potential_evap_rate>959</road_potential_evap_rate> 
  <road_temp_confidence>-3/+3</road_temp_confidence> 
  <dew_point_confidence>-3/+4</dew_point_confidence> 
  <bridge_temp>66</bridge_temp> 
  <bridge_temp_confidence>-3/+3</bridge_temp_confidence> 
  <bridge_frost>NO</bridge_frost> 
  </hour>
+ <hour id="06/02/2009 20:00CDT">
  <air_temp>60</air_temp> 
  <cloud_cover>mostly cloudy</cloud_cover> 
  <dew_point>51</dew_point> 
  <precip_prob>10</precip_prob> 
  <precip_rate>trace</precip_rate> 
  <precip_type>rain</precip_type> 
  <snow_rate>0.0</snow_rate> 
  <wind_direction>ENE</wind_direction> 
  <wind_speed>5</wind_speed> 
  <dew_point_confidence>-3/+4</dew_point_confidence> 
  <road_temp>65</road_temp> 
  <road_frost_prob>0</road_frost_prob> 
  <road_potential_evap_rate>495</road_potential_evap_rate> 
  <road_temp_confidence>-3/+4</road_temp_confidence> 
  <dew_point_confidence>-3/+4</dew_point_confidence> 
  <bridge_temp>62</bridge_temp> 
  <bridge_temp_confidence>-3/+3</bridge_temp_confidence> 
  <bridge_frost>NO</bridge_frost> 
  </hour>
+ <hour id="06/02/2009 21:00CDT">
  <air_temp>57</air_temp> 
  <cloud_cover>mostly cloudy</cloud_cover> 
  <dew_point>51</dew_point> 
  <precip_prob>0</precip_prob> 
  <precip_rate>0.00</precip_rate> 
  <precip_type>none</precip_type> 
  <snow_rate>0.0</snow_rate> 
  <wind_direction>NE</wind_direction> 
  <wind_speed>5</wind_speed> 
  <dew_point_confidence>-3/+4</dew_point_confidence> 
  <road_temp>62</road_temp> 
  <road_frost_prob>0</road_frost_prob> 
  <road_potential_evap_rate>339</road_potential_evap_rate> 
  <road_temp_confidence>-3/+4</road_temp_confidence> 
  <dew_point_confidence>-3/+4</dew_point_confidence> 
  <bridge_temp>59</bridge_temp> 
  <bridge_temp_confidence>-3/+3</bridge_temp_confidence> 
  <bridge_frost>NO</bridge_frost> 
  </hour>
+ <hour id="06/02/2009 22:00CDT">
  <air_temp>56</air_temp> 
  <cloud_cover>mostly cloudy</cloud_cover> 
  <dew_point>51</dew_point> 
  <precip_prob>0</precip_prob> 
  <precip_rate>0.00</precip_rate> 
  <precip_type>none</precip_type> 
  <snow_rate>0.0</snow_rate> 
  <wind_direction>ENE</wind_direction> 
  <wind_speed>5</wind_speed> 
  <dew_point_confidence>-3/+4</dew_point_confidence> 
  <road_temp>60</road_temp> 
  <road_frost_prob>0</road_frost_prob> 
  <road_potential_evap_rate>309</road_potential_evap_rate> 
  <road_temp_confidence>-3/+4</road_temp_confidence> 
  <dew_point_confidence>-3/+4</dew_point_confidence> 
  <bridge_temp>58</bridge_temp> 
  <bridge_temp_confidence>-3/+3</bridge_temp_confidence> 
  <bridge_frost>NO</bridge_frost> 
  </hour>
A: 

Couple things:

  1. I didn't see any elements for County="Adams". The document you gave had county="Adair".

  2. I think you are trying to do a CInt() on a string that looks like <wind_gust>15</wind_gust>.

  3. There is no <wind_gust> element for County Adair and 12:00CDT. So I queried on 15:00CDT, which gave me a wind_gust element. If you query on a time that does not have a wind_gust element, you will get the empty set.

  4. you said you wanted max temp but you are actually querying for wind_gust. I don't see any elements called max_temp.

This code works for me:

Public Sub QueryWindGust(ByVal county As String, ByVal hour As String)
    Dim document = XDocument.Load("meridian.xml")
    Dim selection = From c In document.Root.Elements("county") _
        Where c.Attribute("name").Value = "Adair" _
        From h In c.Elements("hour") _
        Where h.Attribute("id").Value = hour _
        From g In h.Elements("wind_gust") _
        Select CInt(g.Value)


    Console.WriteLine("For county {0}, hour ({1}):", county, hour)
    If (selection.Count > 0)
        Console.Write("wind gust: ")
        For Each m In selection
            Console.WriteLine(m.ToString() & ": (" & m.GetType().ToString() & ")")
        Next
    Else
        Console.WriteLine("No elements returned.")
    End If
End Sub

Public Sub Run()
    QueryWindGust("Adams","06/02/2009 12:00CDT")
    QueryWindGust("Adair","06/02/2009 12:00CDT")
    QueryWindGust("Adair","06/02/2009 15:00CDT")
End Sub
Cheeso