Reputation: 291
Currently, I have the xml as the following:
<Node_Parent>
<Column name="ColA" value="A" />
<Column name="ColB" value="B" />
<Column name="ColC" value="C" />
</Node_Parent>
How to get value B at ColB? I tried to use XmlDocument.SelectSingleNode("Node_Parent")
, but I cannot access to ColB?
If I change to <ColB value="B" />
, I can use XmlDocument.SelectSingleNode("Node_Parent/ColB").Attributes["value"].Value
, but the xml format doesn't look good?
Thanks.
Upvotes: 1
Views: 106
Reputation: 33139
You need to write an XPath query in the SelectSingleNode
:
var value = doc.SelectSingleNode(
"Node_Parent/Column[@name = 'ColB']"
).Attributes["value"].Value;
For more info on the XPath query language, see http://www.w3schools.com/xpath.
Good luck!
Upvotes: 2