Write XML document to file - All Nodes are displayed in a single line


  • Hi,

    I am working on a .NET 4.0 windows application. I use the following code to save the XML document to a file.

    The XML file is saved and I am able to open the XML file. But when I open the file, the all nodes are shown in a single line.

    //form surdoc XML document object and save it using XML writer.

     XmlWriterSettings wSet = new XmlWriterSettings();
                //wSet.NewLineChars = "\r\n";
                wSet.NewLineChars = Environment.NewLine;
                wSet.Encoding = Encoding.UTF8;
                wSet.OmitXmlDeclaration = true;
                wSet.NewLineHandling = NewLineHandling.Replace;           
                XmlWriter tw = XmlWriter.Create(writepath, wSet);

    I want to write the output like this in the file.


    But the Output in the file is like below. All nodes are in a single line.


    How to write XMLdocument into a XML file so that when the file is opened
    childnodes are displayed in the next line?


    Friday, June 21, 2013 9:18 AM

All replies