【发布时间】:2010-09-07 18:16:56
【问题描述】:
我正在使用以下代码将对象序列化为 XML:
public static string SerializeToString<T>(T objectToBeSerialized, string defaultNamespace)
{
StringBuilder stringBuilder = new StringBuilder();
XmlWriterSettings xmlSettings = new XmlWriterSettings()
{
CloseOutput = true,
Indent = true,
OmitXmlDeclaration = true
};
using (XmlWriter xmlWriter = XmlWriter.Create(stringBuilder, xmlSettings))
{
XmlSerializer serializer = new XmlSerializer(typeof(T), defaultNamespace);
serializer.Serialize(xmlWriter, objectToBeSerialized);
return stringBuilder.ToString();
}
}
我已经在设置默认命名空间(“http://schemas.somecompany.com/online/someservice/sync/2008/11”);但是,我的输出仍然包含默认的“xmlns:xsi”和“xmlns:xsd
<RootTag ***xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"*** xmlns="http://schemas.somecompany.com/online/someservice/sync/2008/11">
<SomeTag>
<More>false</More>
</SomeTag>
</RootTage>
我怎样才能摆脱它们?
【问题讨论】:
标签: c# .net xml-serialization