誰能告訴我如何從xml文檔讀取值500?c#XML讀取值
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml ("<move action='bet' value='500' />");
誰能告訴我如何從xml文檔讀取值500?c#XML讀取值
XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml ("<move action='bet' value='500' />");
嘗試類似以下。
string xmlAttributeValue = xmldoc.ChildNodes[0].Attributes["value"].Value
謝謝!有用! – Roy 2010-11-05 03:23:54
隨時歡迎。 :)請考慮將此問題標記爲已回答。 :) – 2010-11-05 03:25:07
你可以得到試試這個
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;
您需要澄清這個問題。 500是哪裏? – vcsjones 2010-11-05 03:03:53
如果您正在討論查詢XML,請嘗試以下操作:http://www.java2s.com/Code/CSharp/XML-LINQ/useLinqtoqueryanXMLdocument.htm – SteveCav 2010-11-05 03:06:05
也請在此處發佈您的xml。 – 2010-11-05 03:10:18