我的XML文档不会保存对该文档所做的更改 [英] My XML document will not save changes made to the document

查看:58
本文介绍了我的XML文档不会保存对该文档所做的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在构建一个应用程序,该应用程序将允许我的用户更改其密码.他们的密码将存储在XML文档中.另外,我计划根据存储在XML文档中的秘密问题进行密码重置.我的代码逐步没有 错误,但XML文档保持不变.

I am building an application that will allow my user to change their password. Their password will be stored in an XML Document. Also, I plan on doing password reset based off of secret questions, stored in an XML document. My code steps-through without error, but the XML document remains unchanged.

在XML文件的属性中,我尝试将复制到输出"设置为作为始终复制"和如果较新则复制",没有运气.

In my properties for the XML file, I have tried to set "Copy to output" as "Copy Always", and "Copy if Newer", no luck.

我的保存代码如下:

XmlDocument XMLdoc = new XmlDocument();
                string XMLfilename = "PasswordHoldDoc.xml";
                XMLdoc.Load(XMLfilename);
                XmlNode root = XMLdoc.DocumentElement;
                String pwdNode = root.FirstChild.InnerText;
                //XmlNode pwdNode = XMLdoc.SelectSingleNode("/directory/password");
                if (pwdNode != null)
                {
                    root.FirstChild.InnerText = passwordConfirmTextbox.Text;
                   
                    XMLdoc.Save("PasswordHoldDoc.xml");
                    MessageBox.Show("done!");

-JG

推荐答案

您未设置保存位置,因此它将与执行程序集保存在同一文件夹中,可能是bin/debug.如果您将其设置为复制到输出,则每次构建时都可能会覆盖它.

You do not set a save location, so it will save in the same folder as the executing assembly, probably bin/debug. If you have it set to copy to output then it is probably overwriting it everytime you build. 

请尝试保存到其他文件夹,以查看您的代码是否还能正常工作.类似于c:\ testfolder \ PasswordHold.xml".

Try saving to a different folder, just to see if you code is even working. Something like c:\testfolder\PasswordHold.xml".

最后,System.Xml.Linq命名空间中的XDocument比XMLDocument更易于使用,并且是更受欢迎的命名空间.

Lastly, XDocument, in the System.Xml.Linq namespace is easier to use and a more preferred namespace than XMLDocument.


这篇关于我的XML文档不会保存对该文档所做的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆