I use xml serialization to create my xml snippets. each serialization does not create linebreak at the end resulting in open tags following close tags. See example output below where the close tag is followed in same line open tag
how can i force the serialization object to be in a new line?
maxmumleewayinticks=Instrument.MasterInstrument.TickSize*2;
string filename="c:\\temp\\Strategyxmlfile" + DateTime.Now.Ticks + ".xml";
settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = " ";
settings.NewLineChars = "\r\n";
settings.NewLineHandling = NewLineHandling.Replace;
settings.OmitXmlDeclaration = true;
settings.CloseOutput = false;
writer= new StreamWriter(filename);
ns.Add("", "");
// write and close the bar
XmlSerializer serializer = new XmlSerializer(typeof( DecisionBar));
w =XmlWriter.Create(writer,settings);
serializer.Serialize(w, decision,ns);
Output:
<DecisionBar EntryOrExit="ENTRY">
<mfe>0.0001</mfe>
<mae>-0.0002</mae>
<bartime>2012-07-25T21:43:00</bartime>
<frequency>1 MINUTES</frequency>
<HH7>true</HH7>
<crossover>true</crossover>
<currentprofitability>0.0001</currentprofitability>
<entryPointLong>1.032</entryPointLong>
<entryPointShort>1.0308</entryPointShort>
<exitStopFull>1.031</exitStopFull>
<exitStopPartial>0</exitStopPartial>
</DecisionBar><DecisionBar>
<mfe>0.0001</mfe>
<mae>-0.0002</mae>
<bartime>2012-07-25T21:44:00</bartime>
<frequency>1 MINUTES</frequency>
<HH7>false</HH7>
<crossover>false</crossover>
<currentprofitability>0.0001</currentprofitability>
<entryPointLong>0</entryPointLong>
<entryPointShort>0</entryPointShort>
<exitStopFull>0</exitStopFull>
<exitStopPartial>0</exitStopPartial>
</DecisionBar>
Take a look here:
This will give you the desired results, although it requires some additional work, not just specifying some options on the XmlSerializer.
Edit: There are a bunch of variations. I found this one Googling; you can do the same.