0

I am serializing objects to XML with the following code:

    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();
        }
    }

I am already setting the default namespace ("http://schemas.somecompany.com/online/someservice/sync/2008/11"); however, my outputs still contain the default "xmlns:xsi" and "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>

How can I get rid of them?

luke
  • 36,103
  • 8
  • 58
  • 81
Bryan
  • 3,220
  • 3
  • 26
  • 31
  • This does sound like - http://stackoverflow.com/questions/258960/how-to-serialize-an-object-to-xml-without-getting-xmlns – Vin Sep 07 '10 at 18:26
  • possible duplicate of [XmlSerializer: remove unnecessary xsi and xsd namespaces](http://stackoverflow.com/questions/760262/xmlserializer-remove-unnecessary-xsi-and-xsd-namespaces) – Hans Olsson Mar 24 '11 at 10:42

1 Answers1

0

XmlSerializer: remove unnecessary xsi and xsd namespaces

Community
  • 1
  • 1
kbrimington
  • 25,142
  • 5
  • 62
  • 74
  • Don't link to weask, instead link to the original SO question at: http://stackoverflow.com/questions/760262/xmlserializer-remove-unnecessary-xsi-and-xsd-namespaces – Hans Olsson Mar 24 '11 at 10:43