Is there any way to save an XmlDocument *without* indentation and line returns?

后端 未结 2 1386
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-19 13:26

All my searches have brought up people asking the opposite, but I have a file which grows by nearly 50% if it is saved with line returns and indentation.

Is there any wa

2条回答
  •  旧巷少年郎
    2021-02-19 13:49

    Use XmlWriterSettings:

    XmlDocument xmlDoc = new XmlDocument();
    [...]
    XmlWriterSettings xwsSettings = new XmlWriterSettings();
    xwsSettings.Indent = false;
    xwsSettings.NewLineChars = String.Empty;
    using (XmlWriter xwWriter = XmlWriter.Create(@"c:\test.xml", xwsSettings))
     xmlDoc.Save(xwWriter);
    

提交回复
热议问题