数据无法保存为XML [英] Data cannot save into XML
问题描述
我有以下代码,允许我将数据保存到xml文件中。我已经调试了代码,一切正常,但是当我打开它时,数据不会出现在xml文件中。关于这里发生了什么的任何想法?
Hi, i have the following codes which allow me to save data into xml file. I have debug the codes and everything is ok, but the data wont appear in the xml file when i open it. Any idea on what has happened here?
XmlNode xRoot, xNode1, xNode2;
XmlDocument xDoc = new XmlDocument();
XmlDocument result = new XmlDocument();
xRoot = xDoc.CreateElement("FTP_Information");
try
{
xNode1 = xDoc.CreateElement("Details");
xNode2 = xDoc.CreateElement("FTP_ID");
xNode2.InnerText = ID;
xNode1.AppendChild(xNode2);
xNode2 = xDoc.CreateElement("FTP_Desc");
xNode2.InnerText = desciption;
xNode1.AppendChild(xNode2);
xNode2 = xDoc.CreateElement("File_Suffix");
xNode2.InnerText = suffix;
xNode1.AppendChild(xNode2);
xNode2 = xDoc.CreateElement("File_Name");
xNode2.InnerText = filename;
xNode1.AppendChild(xNode2);
xNode2 = xDoc.CreateElement("File_Prefix");
xNode2.InnerText = prefix;
xNode1.AppendChild(xNode2);
xNode2 = xDoc.CreateElement("Host");
xNode2.InnerText = host;
xNode1.AppendChild(xNode2);
xNode2 = xDoc.CreateElement("Port");
xNode2.InnerText = port;
xNode1.AppendChild(xNode2);
xNode2 = xDoc.CreateElement("UserID");
xNode2.InnerText = enUser;
xNode1.AppendChild(xNode2);
xNode2 = xDoc.CreateElement("Password");
xNode2.InnerText = enPassword;
xNode1.AppendChild(xNode2);
xRoot.AppendChild(xNode1);
if (xRoot != null)
{
result.LoadXml(xRoot.OuterXml);
// Save the document to a file and auto-indent the output.
XmlTextWriter writer = new XmlTextWriter("ftpSetup.xml", null);
writer.Formatting = Formatting.Indented;
result.Save(writer);
MessageBox.Show("Successful");
}
}
catch(Exception ex)
{
}
推荐答案
什么是数据合约机制?
为什么不阅读呢?
请参阅: http://msdn.microsoft.com/en-us/library/ms733127.aspx [ ^ ]。
要理解为什么我会建议它,而不是直接使用XML,请查看我过去的答案:
创建属性文件...... [ ^ ],
我如何在表单中使用XML文件编写器和阅读器申请? [ ^ ]。
Why not reading about it?
Please see: http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].
To understand why would I suggest it, instead of working with XML directly, please see my past answers:
Creating property files...[^],
How can I utilize XML File streamwriter and reader in my form application?[^].
这篇关于数据无法保存为XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!