【发布时间】:2011-01-18 14:01:14
【问题描述】:
我所有的搜索都提出了相反的问题,但我有一个文件,如果它与换行符和缩进一起保存,它会增长近 50%。
有没有办法解决这个问题?
编辑我说的不是打开一个文件,而是保存一个文件。此代码为我重现了“错误”:
var path = @"C:\test.xml";
System.IO.File.WriteAllText(path, "<root>\r\n\t<line></line>\r\n\t<line></line>\r\n</root>");
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.PreserveWhitespace = false;
doc.Load(path);
doc.PreserveWhitespace = false; //just in case!
doc.Save(path);
中间的断点表明 doc.InnerXml 实际上是 <root><line></line><line></line></root>,正如预期的那样。但是最后test.xml的内容是:
<root>
<line>
</line>
<line>
</line>
</root>
【问题讨论】:
-
(不完全复制/读取与写入 - 相关)
标签: c# .net xmldocument