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

    Question

  • 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);
                surdoc.Save(tw);
                tw.Flush();


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

    <Node1>
       <ChildN1>test1</ChildN1>
     <ChildN2>test2</ChildN2>
    </Node1>

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

    <Node1><ChildN1>test1</ChildN1><ChildN2>test2</ChildN2></Node1>

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

    Thanks
    Ashok

    Friday, June 21, 2013 9:18 AM

All replies