开发者

.net: XmlDocument creates one line xml document

开发者 https://www.devze.com 2023-01-26 07:26 出处:网络
I have a standard XML document, which looks like a \'tree\'. I add some nodes and save changes: XmlDocument doc = new XmlDocument();

I have a standard XML document, which looks like a 'tree'. I add some nodes and save changes:

    XmlDocument doc = new XmlDocument();    
    doc.Load(filename);
 ...
    doc.PreserveWhitespace = true;
    XmlText开发者_运维问答Writer writer = new XmlTextWriter(filename, Encoding.Default); 
    doc.WriteTo(writer);
    writer.Close();     

and after that xml document stretch into one line. How to add line feeds?


After you construct the XmlTextWriter, but before you call doc.WriteTo(writer);, insert this line:

writer.Formatting = Formatting.Indented; 
0

精彩评论

暂无评论...
验证码 换一张
取 消