我使用 xml 序列化来创建我的 xml 片段。每个序列化不会在最后创建换行符,从而导致打开标签跟随关闭标签。请参阅下面的示例输出,其中在同一行打开标记中跟随关闭标记
我如何强制序列化对象位于新行中?
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);
输出:
<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>