开发者

c# XML read value

开发者 https://www.devze.com 2023-01-24 03:01 出处:网络
Can anyone tell me how to read the value 500 from the xml document, please? XmlDocument xmldoc = new XmlDocum开发者_JAVA技巧ent();

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

0

精彩评论

暂无评论...
验证码 换一张
取 消