开发者

.net: XmlDocument creates one line xml document

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜