Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.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
C# 如何在C中从XmlNode获取参数值#_C#_Xml - Fatal编程技术网

C# 如何在C中从XmlNode获取参数值#

C# 如何在C中从XmlNode获取参数值#,c#,xml,C#,Xml,如何获取XmlNode标记中的参数值。例如: <weather time-layout="k-p24h-n7-1"> <name>Weather Type, Coverage, and Intensity</name> <weather-conditions weather-summary="Mostly Sunny"/> </weather> 天气类型、覆盖范围和强度 我想获取节点“weather conditi

如何获取XmlNode标记中的参数值。例如:

<weather time-layout="k-p24h-n7-1">
    <name>Weather Type, Coverage, and Intensity</name>
    <weather-conditions weather-summary="Mostly Sunny"/>
</weather>

天气类型、覆盖范围和强度

我想获取节点“weather conditions”中参数“weather summary”的值

为了完整起见,还应给出.Net 3.5方式:

var node = xmldoc.SelectSingleNode("weather/weather-conditions");
var attr = node.Attributes["weather-summary"];
假定

XDocument doc = XDocument.Parse(@"<weather time-layout='k-p24h-n7-1'>
    <name>Weather Type, Coverage, and Intensity</name>
    <weather-conditions weather-summary='Mostly Sunny'/></weather>");

我会给你同样的答案

return doc.Element("weather").Element("weather-conditions").Attribute("weather-summary").Value;
return doc.Descendants("weather-conditions").First().Attribute("weather-summary").Value;