How do I set the Settings property in XmlTextWriter, so that I can write each XML attribute on its own line?
Use the static Create()
method of XmlWriter
.
XmlWriter.Create(filePath, settings);
Note that you can set the NewLineOnAttributes
property in the settings.
I know the question is old, anyway it's actually possible to set indentation for the XMLTextWriter
. Unlike with the XMLwriter
, you don't have to pass through the settings; you should use the Formatting
property:
XmlTextWriter writer = new XmlTextWriter(filePath, Encoding.UTF8);w.Formatting = Formatting.Indented;
Seehttps://msdn.microsoft.com/en-us/library/system.xml.xmltextwriter.formatting(v=vs.110).aspx