c#XML读取值
有谁能告诉我如何从xml文档中读取值500吗c#XML读取值,c#,xml,C#,Xml,有谁能告诉我如何从xml文档中读取值500吗 XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml ("<move action='bet' value='500' />"); XmlDocument xmldoc=new XmlDocument(); xmldoc.LoadXml(“”); LINQ-to-XMLLINQ-to-XML尝试以下方法 string xmlAttributeValue = xmldoc.Chi
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml ("<move action='bet' value='500' />");
XmlDocument xmldoc=new XmlDocument();
xmldoc.LoadXml(“”);
LINQ-to-XMLLINQ-to-XML尝试以下方法
string xmlAttributeValue = xmldoc.ChildNodes[0].Attributes["value"].Value
试试下面的方法
string xmlAttributeValue = xmldoc.ChildNodes[0].Attributes["value"].Value
你可以试试这个
string attVal = xmldoc.GetElementsByTagName("move")[0].Attributes["value"].Value
你可以试试这个
string attVal = xmldoc.GetElementsByTagName("move")[0].Attributes["value"].Value
这也可能奏效:
//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;
这也可能奏效:
//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;
你需要澄清这个问题。500在哪里?如果您正在谈论查询XML,请尝试以下方法:请在此处发布您的XML。抱歉,此处没有显示XML。我必须在“移动”之前添加一个空格。如果你发布代码或XML,你需要在文本编辑器中突出显示这些行,然后单击编辑器工具栏上的“代码”按钮(101 010),以很好地格式化和语法突出显示它们。你需要澄清这个问题。500在哪里?如果您正在谈论查询XML,请尝试以下方法:请在此处发布您的XML。抱歉,此处没有显示XML。我必须在“移动”之前添加一个空格。如果您发布代码或XML,则需要在文本编辑器中突出显示这些行,然后单击编辑器工具栏上的“代码”按钮(101 010),以很好地格式化和语法突出显示它们(始终欢迎):请考虑回答这个问题。永远欢迎。:)请考虑回答这个问题。