Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get parameter values from an XmlNode in C#

Tags:

c#

xml

How do I get the values for parameters in a XmlNode tag. For example:

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

I want to get the value for the parameter 'weather-summary' in the node 'weather-conditions'.

like image 311
Brian Avatar asked Dec 23 '22 04:12

Brian


1 Answers

var node = xmldoc.SelectSingleNode("weather/weather-conditions");
var attr = node.Attributes["weather-summary"];
like image 170
Dean Harding Avatar answered Jan 06 '23 16:01

Dean Harding