I have the following XML:
<NET_SETTINGS>
<MAC_ADDRESS VALUE="bb:cc:dd:ee:ff:aa"/>
<IP_ADDRESS VALUE="10.1.1.1"/>
</NET_SETTINGS>
and trying to get the string VALUE of either mac/ip element like so:
XmlNode macnode = xmlDoc.SelectSingleNode("/NET_SETTINGS/IP_ADDRESS");
string mac = macnode.Value;
I can see that it selects the correct node while stepping through the code, but the macnode.Value is always null and the OuterXml is this:
"<MAC_ADDRESS VALUE=\"bb:cc:dd:ee:ff:aa\" />"
Why does Value not get populated correctly?
.ValueisnullforElementnodes.You want
macnode.Attributes.GetNamedItem("VALUE").Value