I am wondering how to add a line break for each element when using XmlSerializer?
Sample code:
XmlSerializer serializer = new XmlSerializer(typeof(xxx));
using (XmlWriter xmlWriter = XmlWriter.Create("test.xml")
{
serializer.Serialize(xmlWriter, xxx);
}
You can use XmlWriterSettings and set the properties to out the indentation and newlines. .Indent and .NewLineOnAttributes seem to be what you would want.
http://msdn.microsoft.com/en-us/library/system.xml.xmlwritersettings.aspx
When creating the
XmlWriter
, pass in anXmlWriterSettings
object withIndent
set totrue
.