I\'m using DatacontractSerializer
to serialize my domainModel into a xml file.
I\'m getting output like below.
You should be able to get rid of those prefixes by just making sure that the classes that you are trying to serialize to XML are within the same Namespace. For example I had two classes ApplicationListResponse and Application. Previously the namespaces were Models.Responses and Models.Responses.Application. I changed both of the Namespaces to be "Models" and that got rid of the prefix in the XML output.
Using an empty namespace seems to remove the prefix. Setup your class with the following DataContract attribute:
[DataContract(Namespace="")]
public class MyClass
{ ... }
Then be sure to set the namespace to an empty string when (de)serializing:
DataContractSerializer deserializer = new DataContractSerializer(typeof(MyClass), typeof(MyClass).Name, "");
It looks like DataContractSerializer
doesn't give much control over prefixes. The answer to XML Serialization and namespace prefixes suggests using XmlSerializer
if you want to control the namespace prefix.
Your question wasn't clear as to whether you wanted to entirely remove the namespace prefixes for your domain model. Your sample above has several namespace prefixes: d1p1, d2p1, d4p1. Changing namespace for XML file in XSL Translation provides some guidance on prefix renaming using XSLT.