XML : Error to output data

I´m trying to get data from this XML:

  <data num_results="2">  <METAR>  <raw_text>  LEMD 171630Z 16005KT 080V220 CAVOK 07/M02 Q1023 NOSIG  </raw_text>  <station_id>LEMD</station_id>  <observation_time>2016-01-17T16:30:00Z</observation_time>  <latitude>40.48</latitude>  <longitude>-3.57</longitude>  <temp_c>7.0</temp_c>  <dewpoint_c>-2.0</dewpoint_c>  <wind_dir_degrees>160</wind_dir_degrees>  <wind_speed_kt>5</wind_speed_kt>  <visibility_statute_mi>6.21</visibility_statute_mi>  <altim_in_hg>30.206694</altim_in_hg>  <quality_control_flags>  <no_signal>TRUE</no_signal>  </quality_control_flags>  <sky_condition sky_cover="CAVOK"/>  <flight_category>VFR</flight_category>  <metar_type>METAR</metar_type>  <elevation_m>582.0</elevation_m>  </METAR>  

The problem to output data from textbox appears this error:

Error 1 'result' is not member of'System.Collections.Generic.IEnumerable(Of )'.

Here the code used:

    Try          'Si la conexión está OK, parsear XML          Dim metarxml As XDocument = XDocument.Load(webstream)            Dim dataresult = (From data In metarxml.Descendants("data")                Select New With {Key .result = data.Attribute("num_results").Value})          If testtxt.Text = 0 Then              MessageBox.Show("The airport does´t exist.")          End If            Dim metar = (From x In metarxml.Descendants("METAR")                Select New With {Key .rawtext = x.Element("raw_text").Value,                                 Key .windirection = x.Element("wind_dir_degrees").Value,                                 Key .windspeed = x.Element("wind_speed_kt").Value,                                 Key .tempc = x.Element("temp_c").Value,                                 Key .dewpoint = x.Element("dewpoint_c").Value,                                 Key .obstime = x.Element("observation_time").Value,                                 Key .pressure = x.Element("altim_in_hg").Value                                }).FirstOrDefault()            testtxt.Text = dataresult.result          winddirdegreestxt.Text = metar.windirection & " °"          windspeedtxt.Text = metar.windspeed & " knots"          temperaturetxt.Text = metar.tempc & " °C"          dewpointtxt.Text = metar.dewpoint & " °C"          obstimetxt.Text = metar.obstime & " UTC"          pressuretxt.Text = metar.pressure        Catch ex As System.Xml.XmlException          MessageBox.Show(ex.Message)      End Try    

I don´t know why it shows this error message.

Thanks in advance Regards

No comments:

Post a Comment