Jak používat Kde klauzule tak, aby odpovídala stavu DateTime

hlasů
0

Níže dotaz funguje dobře pro mě, dokud jsem se vztahují Wherepodmínku Hours přívlastkem Id= '06/02/2009 12:00CDT'.

Musím se dostat na maximální teplotě po dobu jediného dnešního dne, a já nejsem schopen používat Wherepodmínku v poli datum. Jakékoli myšlenky na to, co dělám špatně?

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

Níže je 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>
Položena 26/08/2009 v 22:30
zdroj uživatelem
V jiných jazycích...                            


1 odpovědí

hlasů
1

Pár věcí:

  1. Neviděl jsem žádné prvky pro krajské = „Adams“. Dokument, který dal měl kraj = „Adair“.

  2. Myslím, že se snažíte dělat CInt () na řetězec, který vypadá <wind_gust>15</wind_gust>.

  3. Neexistuje žádný <wind_gust>prvek pro hrabství Adair a 12: 00CDT. Tak jsem se dotázat na 15: 00CDT, který mi dal wind_gust prvek. Jestliže dotaz na době, která nemá wind_gust prvek, dostanete prázdnou množinu.

  4. jste řekl, že jste chtěl Max Temp, ale ty jsou skutečně dotazování wind_gust. Nevidím žádné prvky zvané max_temp.

Tento kód funguje pro mě:

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
Odpovězeno 26/08/2009 v 22:49
zdroj uživatelem

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more