2
我已經使用XmlSerializer序列化對象,並在我的輸出中接收不需要的名稱空間屬性。我如何防止它在XML中打印這些名稱空間?如何用XML序列化來壓縮名稱空間的輸出?
// write and close the bar
XmlSerializer serializer = new XmlSerializer(typeof(DecisionBar));
serializer.Serialize(writer, decision);
public class DecisionBar
{
public DateTime bartime { get; set; }
public string frequency { get; set; }
public bool HH7 { get; set; }
public bool crossover { get; set; }
public double mfe { get; set; }
public double mae { get; set; }
public double entryPointLong { get; set; }
public double entryPointShort { get; set; }
}
輸出:
<DecisionBar xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<bartime>2012-07-23T07:22:00</bartime>
<frequency>1 MINUTES</frequency>
<HH7>true</HH7>
<crossover>false</crossover>
<mfe>0</mfe>
<mae>0</mae>
<entryPointLong>1.2139</entryPointLong>
<entryPointShort>1.212</entryPointShort>
</DecisionBar>
此外,'VAR NS =新XmlSerializerNamespaces(新[] {XmlQualifiedName.Empty});'如果單行激發你。 – Marc 2012-07-23 14:37:22
@marc很可愛;我不能說我之前注意到了XmlQualifiedName.Empty。 – 2012-07-23 14:39:37
我該如何擺脫<?xml version =「1.0」encoding =「utf-8」?>那裏呢? – junkone 2012-07-23 16:52:47