可能性の重複:
How to remove whitespace from an XmlDocument*インデントなしでXmlDocument *を保存する方法はありますか?
すべての私の検索は、反対を尋ねる人を育ててきたが、それは改行で保存されている場合、私は50%近く成長したファイルを持っており、インデント。
これには何らかの方法がありますか?
EDIT私は約開口部ファイルを話していないんだけど、は 1を保存します。このコードは、私のための「バグ」を再現:
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>
http://stackoverflow.com/の可能性のある擬似重複質問/ 2035252/how-to-save-xmldocument-multiple-indentation-settings –
(完全なdup/read対* write *関連) –