The problem:
I have created a WebApi and need to support XML.
The default DataContractSerializer generates namespaces like:
xmlns:d2p1="http://schemas.datacontract.org/2004/07/Vendor.App.Model.DeeperModel"
xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
I don't want to have these namespaces in my XML. Its very hard to work with them.
In my case I need to support XLST from FileMaker, which has problems with namespaces other XLS Parsers do not have.
What I have found, but is not a duplicate for later statet reasons:
I have read about it here, here and other locations in the web.
I only found this two advices:
- Use
[DataContract(Namespace = "")]
-Attribute - Use XmlSerializer
- by extending
XmlMediaTypeFormatter
- by setting
config.Formatters.XmlFormatter.UseXmlSerializer = true
- by extending
DataContract:
DataContract Attribute does not work good for classes I have no control. I do not want to do this ugly hack:
[DataContract(Namespace = "")]
IThisIsNonesense<T> : IEnumerable<T>
{
}
[DataContract(Namespace = "")]
ThisIsNonesense<T> : List<T>, IThisIsNonesense<T>
{
public ThisIsNonesense() : base() {}
}
XmlSerializer:
XmlSerializer is not very flexible. For example it does not support Interface. I make for example heavy use of IEnumerable<T>
.
My Question:
How is it possible to remove all Namespaces by default, without making changes through the whole codebase? If it is not possible what would you advice?