Comment utiliser la clause Where pour correspondre à la condition DateTime

voix
0

Ci - dessous la requête fonctionne bien pour moi jusqu'à ce que j'applique Wherecondition Houravec l' attribut Id= '06/02/2009 12:00CDT'.

Je dois obtenir la température max pour la date d'aujourd'hui seulement, et je ne suis pas en mesure d'utiliser la Wherecondition dans le champ de date. Toutes les idées sur ce que je fais mal?

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

Voici le 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>
Créé 26/08/2009 à 22:30
source utilisateur
Dans d'autres langues...                            


1 réponses

voix
1

deux choses:

  1. Je ne vois pas d'éléments pour County = « Adams ». Le document a eu le comté = « Adair ».

  2. Je pense que vous essayez de faire un CInt () sur une chaîne qui ressemble <wind_gust>15</wind_gust>.

  3. Il n'y a pas l' <wind_gust>élément pour le comté de Adair et 12: 00CDT. Alors j'ai demandé le 15: 00CDT, ce qui m'a donné un élément de wind_gust. Si vous interrogez sur un temps qui ne dispose pas d' un élément wind_gust, vous obtiendrez l'ensemble vide.

  4. vous avez dit que vous vouliez température max mais vous interrogez réellement pour wind_gust. Je ne vois pas d'éléments appelés max_temp.

Ce code fonctionne pour moi:

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
Créé 26/08/2009 à 22:49
source utilisateur

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