【发布时间】:2013-12-13 00:13:56
【问题描述】:
我是第一次使用 xml,并且一直被它的保存/加载方面所困扰。我希望在应用程序关闭时将文本框中的信息保存到 xml 文件中,但是当应用程序运行时,我无法使用右上角的“X”关闭应用程序。我尝试删除 xml 文件和重新创建它,但这仍然没有帮助。
我现在关闭了应用程序,保存功能确实适用于 xml。然而,加载函数并没有通过它的 foreach 循环将 xml 中的信息添加回应用程序
XmlDocument xDoc = new XmlDocument();
xDoc.Load(path + place);
foreach( XmlNode xNode in xDoc.SelectNodes("ClientMeasurements\\Client"))
{
Client c = new Client();
c.Name = xNode.SelectSingleNode("Name").InnerText;
c.InitialForearm = xNode.SelectSingleNode("InitialForearm").InnerText;
c.InitialUpperArmR = xNode.SelectSingleNode("InitialUpperArmRight").InnerText;
c.InitialUpperArmL = xNode.SelectSingleNode("InitialUpperArmLeft").InnerText;
c.InitialChest = xNode.SelectSingleNode("InitialChest").InnerText;
c.InitialWaist = xNode.SelectSingleNode("InitialWaist").InnerText;
c.InitialHips = xNode.SelectSingleNode("InitialHips").InnerText;
c.InitialThighR = xNode.SelectSingleNode("InitialThighRight").InnerText;
c.InitialThighL = xNode.SelectSingleNode("InitialThighLeft").InnerText;
c.InitialCalfR = xNode.SelectSingleNode("InitialCalfRight").InnerText;
c.InitialCalfL = xNode.SelectSingleNode("InitialCalfLeft").InnerText;
c.MostRecentForearm = xNode.SelectSingleNode("MostRecentForearm").InnerText;
c.MostRecentUpperArmR = xNode.SelectSingleNode("MostRecentUpperArmRight").InnerText;
c.MostRecentUpperArmL = xNode.SelectSingleNode("MostRecentUpperArmLeft").InnerText;
c.MostRecentChest = xNode.SelectSingleNode("MostRecentChest").InnerText;
c.MostRecentWaist = xNode.SelectSingleNode("MostRecentWaist").InnerText;
c.MostRecentHips = xNode.SelectSingleNode("MostRecentHips").InnerText;
c.MostRecentThighR = xNode.SelectSingleNode("MostRecentThighRight").InnerText;
c.MostRecentThighL = xNode.SelectSingleNode("MostRecentThighLeft").InnerText;
c.MostRecentCalfR = xNode.SelectSingleNode("MostRecentCalfRight").InnerText;
c.MostRecentCalfL = xNode.SelectSingleNode("MostRecentCalfLeft").InnerText;
client.Add(c);
listView1.Items.Add(c.Name);
}
}
【问题讨论】:
-
不能点击关闭按钮是什么意思?是不是变灰了?单击它时它会挂起吗?
-
当我点击它时应用程序没有响应。它没有变灰,按钮单击,但不会关闭应用程序。
-
你试过下断点,看看哪一行代码或方法调用有问题吗?
-
否,因为应用程序运行良好,但不会关闭并保存到 xml 文件。我认为断点仅适用于代码导致崩溃的地方
-
调试您的代码 - 放置断点并逐步查看发生了什么...如果它没有帮助 - 制作重现问题的 small 示例(查看 @ 987654321@) - 现在你有很多几乎相同的代码行,没有添加任何关于问题的新信息。旁注:带空格的节点名称对于 XML 来说是一种不寻常的做法,并且在创建节点时会导致错误,我假设您的节点名称只是示例而不是真实的。