Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#XML读取值_C#_Xml - Fatal编程技术网

c#XML读取值

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

有谁能告诉我如何从xml文档中读取值500吗

XmlDocument xmldoc = new XmlDocument(); 

xmldoc.LoadXml ("<move action='bet' value='500' />");
XmlDocument xmldoc=new XmlDocument();
xmldoc.LoadXml(“”);

LINQ-to-XML

LINQ-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),以很好地格式化和语法突出显示它们(始终欢迎):请考虑回答这个问题。永远欢迎。:)请考虑回答这个问题。