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?
Usually it suffices to simply use the Save method of an XmlDocument e.g.
If you want to use an XmlWriter and want indentation then obviously you should use XmlWriterSettings with
http://msdn.microsoft.com/en-us/library/system.xml.xmlwritersettings.indent.aspx being set:
wSet.Indent = true;
MVP (XML, Data Platform Development) 2005/04 - 2013/03
Microsoft is conducting an online survey to understand your opinion of the Msdn Web site. If you choose to participate, the online survey will be presented to you when you leave the Msdn Web site.
Would you like to participate?