我有以下代码。如何从 XML 文件中获取云的值?刚试了一下。该列表填充了正确数量的元素,但它们都是空的。
XDocument xdoc = XDocument.Parse(e.Result, LoadOptions.None);
List<string> list = new List<string>();
foreach (XElement element in xdoc.Root.Elements("forecast").Elements("time"))
{
list.Add((string)element.Attribute("time"));
}
xml文件:
<weatherdata>
<location>
<name>Dronten</name>
<type/>
<country>NL</country>
<timezone/>
<location altitude="0" latitude="52.525002" longitude="5.71806" geobase="geonames" geobaseid="0"/>
</location>
<credit/>
<meta>
<lastupdate>2013-06-20T17:30:39</lastupdate>
<calctime>0.0547</calctime>
<nextupdate>2013-06-20T20:30:39</nextupdate>
</meta>
<sun rise="2013-06-20T03:13:40" set="2013-06-20T20:04:01"/>
<forecast>
<time from="2013-06-20T15:00:00" to="2013-06-20T18:00:00">
<symbol number="801" name="few clouds" var="02d"/>
<precipitation/>
<windDirection deg="43.5014" code="NE" name="NorthEast"/>
<windSpeed mps="6.9" name="Moderate breeze"/>
<temperature unit="celsius" value="19.71" min="19.71" max="26.517"/>
<pressure unit="hPa" value="1022.12"/>
<humidity value="62" unit="%"/>
<clouds value="few clouds" all="24" unit="%"/>
</time>
<time from="2013-06-20T18:00:00" to="2013-06-20T21:00:00">
<symbol number="501" name="moderate rain" var="10d"/>
<precipitation value="10.5" unit="3h" type="rain"/>
<windDirection deg="18.0018" code="NNE" name="North-northeast"/>
<windSpeed mps="3.72" name="Gentle Breeze"/>
<temperature unit="celsius" value="13.24" min="13.24" max="19.706"/>
<pressure unit="hPa" value="1021.71"/>
<humidity value="100" unit="%"/>
<clouds value="overcast clouds" all="92" unit="%"/>
</time>
</forecast>
</weatherdata>