Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';无法从C#(Windows phone 8)中的xml文件获取数据_C#_Xml_Windows Phone 8 - Fatal编程技术网

Can';无法从C#(Windows phone 8)中的xml文件获取数据

Can';无法从C#(Windows phone 8)中的xml文件获取数据,c#,xml,windows-phone-8,C#,Xml,Windows Phone 8,我有以下代码。如何从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")) {

我有以下代码。如何从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"));

 }
XDocument xdoc=XDocument.Parse(例如,Result,LoadOptions.None);
列表=新列表();
foreach(xdoc.Root.Elements(“预测”).Elements(“时间”)中的XElement元素)
{
添加((字符串)element.Attribute(“时间”);
}
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>

德龙腾
NL
2013-06-20T17:30:39
0.0547
2013-06-20T20:30:39

您必须调用
属性

此外,
时间
节点中属性的名称是
“从”
“到”
;我没有看到任何一个名字是“时间”

Add
语句更改为:

list.Add(element.Attribute("from").Value);
我是你的朋友

XmlNode foo = xdoc.SelectSingleNode("/weatherdata/forecast/time/clouds");

您是否尝试过使用调试器,并查看到底有什么不起作用?谢谢,这就是问题所在:)