gpt4 book ai didi

c# - 如何通过 XML 序列化抑制 namespace 的输出?

转载 作者:行者123 更新时间:2023-12-02 22:34:44 25 4
gpt4 key购买 nike

我已经使用 XmlSerializer 序列化了一个对象,并且在我的输出中收到不需要的命名空间属性。我怎样才能阻止它在 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 = new XmlSerializerNamespaces();
ns.Add("", "");
serializer.Serialize(writer, decision, ns);

关于c# - 如何通过 XML 序列化抑制 namespace 的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11614569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com