c# XML read value
Can anyone tell me how to read the value 500 from the xml document, please?
XmlDocument xmldoc = new XmlDocum开发者_JAVA技巧ent();
xmldoc.LoadXml ("<move action='bet' value='500' />");
try something like following.
string xmlAttributeValue = xmldoc.ChildNodes[0].Attributes["value"].Value
You could get try this
string attVal = xmldoc.GetElementsByTagName("move")[0].Attributes["value"].Value
This could work too:
//Select the node with action='bet'
XmlNode node = xmldoc.SelectSingleNode("/move[@action='bet']");
// Read the value of the Attribute 'value'
var value = node.Attributes["value"].Value;
LINQ to XML http://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx
精彩评论