我使用以下代码将对象序列化为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>
我怎样摆脱它们?