Tuesday, 15 September 2015

Can't get data from xml file in C# (Windows phone 8) -


I have the following code: How do I get the values ​​of clouds from an XML file? Just a little while, the list is full of the correct number of elements, but they are empty.

  XDocument xdoc = XDocument.Parse (e.Result, LoadOptions.None); & Lt; String & gt; List = new list & lt; String & gt; (); Leading (Excl. Elements ("prediction") elements ("time")) {list.Add (string) element. Attribute ("time")); }   

XML file:

  & lt; WeatherData & gt; & Lt; Location & gt; & Lt; Name & gt; Dronten & lt; / Name & gt; & Lt; Type / & gt; & Lt; Country & gt; NL & lt; / Country & gt; & Lt; Time zone / & gt; & Lt; Location height = "0" latitude = "52.525002" longitude = "5.71806" geobase = "geonames" geobaseid = "0" /> & Lt; / Location & gt; & Lt; Credit /> & Lt; Meta & gt; & Lt; LASTUPDATE & gt; 2013-06-20T17: 30: 39 & lt; / LASTUPDATE & gt; & Lt; Calctime & gt; 0.0547 & lt; / Calctime & gt; & Lt; Nextupdate & gt; 2013-06-20T20: 30: 39 & lt; / Nextupdate & gt; & Lt; / Meta & gt; & Lt; Sun rise = "2013-06-20T03: 13: 40" set = "2013-06-20T20: 04: 01" /> & Lt; Forecast & gt; & Lt; Time = "2013-06-20T15: 00: 00" to = "2013-06-20T18: 00: 00" & gt; & Lt; Symbol number = "801" name = "some cloud" var = "02d" /> & Lt; Rain /> & Lt; Windderection degree = "43.5014" code = "NE" name = "NorthEast" /> & Lt; Windspeed MPS = "6.9" name = "medium air" /> & Lt; Temperature unit = "celsius" value = "19.71" m = "19.71" max = "26.517" /> & Lt; Pressure unit = "hpa" value = "1022.12" /> & Lt; Humidity value = "62" unit = "%" /> & Lt; Cloud value = "some clouds" all = "24" unit = "%" /> & Lt; / Time & gt; & Lt; Time = "2013-06-20T18: 00: 00" to = "2013-06-20T21: 00: 00" & gt; & Lt; Symbol number = "501" name = "moderate rainfall" var = "10d" /> & Lt; Rainfall value = "10.5" unit = "3h" type = "rain" /> & Lt; Winding degree = "18.0018" code = "nn" name = "north-northeast" /> & Lt; Wind speed MPS = "3.72" name = "gentle breeze" /> & Lt; Temperature unit = "celsius" value = "13.24" min = "13.24" max = "19.706" /> & Lt; Pressure unit = "hpa" value = "1021.71" /> & Lt; Humidity value = "100" unit = "%" / & gt; & Lt; Cloud price = "overcast clouds" all = "92" unit = "%" /> & Lt; / Time & gt; & Lt; / Predictions & gt; & Lt; / Weatherdata>    

You must call the value property.

Additionally, the names of attributes in your time nodes are "to" and by "; I do not see any of them with the name "time" .

Change your add statement to:

  list.Add (element.Attribute ("from") value.);    

No comments:

Post a Comment