C#XML读写器 [英] C# XML reader and writer
本文介绍了C#XML读写器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这适用于读取XML文档,但不能编写.我究竟做错了什么.我查找了错误,不确定如何纠正错误,非常感谢您的帮助:)-LTooze
空白处理存在问题,我无法解决
This works for reading in an XML document, but not writing. What am I doing wrong. I''ve looked up the errors and am unsure on how to correct them, much help would be appreciated thank you :) - LTooze
Theres an issue with the whitespacehandling, which i am unable to solve
public void XMLWrite_Click(object sender, EventArgs e)
{
XmlDataDocument xmlDatadoc = new XmlDataDocument();
xmlDatadoc.DataSet.WriteXml(txtXMLFilePath.Text);
DataSet ds = new DataSet("Book DataSet");
ds = xmlDatadoc.DataSet;
dataGridView1.DataSource = ds.DefaultViewManager;
dataGridView1.DataMember = "Book";
if (File.Exists(txtXMLFilePath.Text))
{
XmlTextWriter writer = new XmlTextWriter(txtXMLFilePath.Text);
writer.WhitespaceHandling = WhitespaceHandling.None;
writer.Close();
}
else
{
MessageBox.Show(txtXMLFilePath.Text + " Error Writing XmlFile");
}
推荐答案
您没有尝试写任何东西,那么您如何期望某些东西可以起作用"呢?另外,为什么还要检查该文件是否存在?是否存在如果没有,它将创建,如果没有,它将被覆盖.
—SA
You are not trying to write anything, so how can you expect something to "work"? Also, why would you check up that the file exists? If may exist or not; it if does not, it will be created, if not — overwritten.
—SA
这篇关于C#XML读写器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文