C# 如何控制XmlSerializer添加默认命名空间的位置
我试图控制将默认名称空间添加到C# 如何控制XmlSerializer添加默认命名空间的位置,c#,namespaces,xmlserializer,C#,Namespaces,Xmlserializer,我试图控制将默认名称空间添加到XmlSerializer的输出中的级别 到目前为止我已经 <GetAccountDetailRequestStructure> <AccountRef xmlns="http://www.govtalk.gov.uk/NAC/GetAccountDetail">4026069</AccountRef> <AccountType xmlns="http://www.govtalk.gov.uk/NAC/GetAcco
XmlSerializer
的输出中的级别
到目前为止我已经
<GetAccountDetailRequestStructure>
<AccountRef xmlns="http://www.govtalk.gov.uk/NAC/GetAccountDetail">4026069</AccountRef>
<AccountType xmlns="http://www.govtalk.gov.uk/NAC/GetAccountDetail">C</AccountType>
<SelectionOptions xmlns="http://www.govtalk.gov.uk/NAC/GetAccountDetail">
<FromDate>2000-01-01</FromDate>
<ToDate>2015-10-23</ToDate>
<IncludeAccountSummary>false</IncludeAccountSummary>
</SelectionOptions>
</GetAccountDetailRequestStructure>
但我想得到的是
<GetAccountDetailRequestStructure xmlns="http://www.govtalk.gov.uk/NAC/GetAccountDetail">
<AccountRef>4026069</AccountRef>
<AccountType>C</AccountType>
<SelectionOptions>
<FromDate>2000-01-01</FromDate>
<ToDate>2015-10-23</ToDate>
<IncludeAccountSummary>false</IncludeAccountSummary>
</SelectionOptions>
</GetAccountDetailRequestStructure>
4026069
C
2000-01-01
2015-10-23
假的
我认为这相当于第一个XML示例尝试将默认名称空间传递给
XmlSerializer
的
const string defaultNamespace = "http://www.govtalk.gov.uk/NAC/GetAccountDetail";
var ns = new XmlSerializerNamespaces();
ns.Add(string.Empty, defaultNamespace);
// Note the 2nd constructor argument.
var xs = new XmlSerializer(typeof(T), defaultNamespace);
xs.Serialize(xmlWriter, obj, ns);
它们不是等价物。在第一个示例中,
GetAccountDetailRequestStructure
位于全局命名空间中。@Damien\u the\u Noisever OK,如果是全局命名空间,如何在XmlSerializer中控制它
const string defaultNamespace = "http://www.govtalk.gov.uk/NAC/GetAccountDetail";
var ns = new XmlSerializerNamespaces();
ns.Add(string.Empty, defaultNamespace);
// Note the 2nd constructor argument.
var xs = new XmlSerializer(typeof(T), defaultNamespace);
xs.Serialize(xmlWriter, obj, ns);