Remove Ambient Namespaces From Serialized XML
Currently the XML serialisers both output namespaces that are not required:
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
I'm not sure about the Data Contract serializer, but it is not difficult to supress these...
Just pass into the Serialize method an XmlSerializerNamespaces:
var xmlSerializerNamespaces = new XmlSerializerNamespaces();
xmlSerializerNamespaces.Add(String.Empty, defaultNamespace);
var xmlSerializer = new XmlSerializer(objectType);
xmlSerializer.Serialize(xmlWriter, toBeSerialised, xmlSerializerNamespaces);
Where defaultNamespace could be set on the GlobalConfiguration.Configuration.Formatters.XmlFormatter or it could be read from the XmlRoot attribute (if present) on the object being serialised.
We are looking at exposes settings to control this behavior on the XML formatter
1 comment
-
Piers
commented
For "but it is not difficult to supress these" read "but it is not difficult to supress these on the XmlSerializer"