【发布时间】:2014-05-28 11:03:13
【问题描述】:
在 c# 中将子节点文本放入富文本框中时遇到问题。到目前为止,这是我尝试过的:
这是 XML 文件:
<DATA_LIST>
<Customer>
<Full_Name>TEST</Full_Name>
<Total_Price>100</Total_Price>
<Discounts>20</Discounts>
</Customer>
</DATA_LIST>
代码
//Loads XML Document
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
XmlDocument xDoc = new XmlDocument();
xDoc.Load(path + "\\Origami - User\\info.xml");
//My attempt at selecting a child node and making it a string
XmlNode xNode = xDoc.SelectSingleNode("DATA_LIST\\Customer");
string TotalPriceString = xNode.SelectSingleNode("Total_Price").InnerText;
txtLogBox.AppendText("test: " + TotalPriceString);
这是我得到的错误:
“System.Xml.XPath.XPathException”类型的未处理异常 发生在 System.Xml.dll 中
附加信息:“DATA_LIST\Customer”的令牌无效。
任何帮助都会很棒。
【问题讨论】: