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

后端 未结 2 1351
佛祖请我去吃肉
佛祖请我去吃肉 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 14:08

    Try this code:

    XmlDocument doc = new XmlDocument();
    
    using(XmlTextWriter wr = new XmlTextWriter(fileName, Encoding.UTF8))
    {
        wr.Formatting = Formatting.None; // here's the trick !
        doc.Save(wr);
    }
    

提交回复
热议问题