Remove “d1p1” namespace prefix in DataContractSerializer XML output

前端 未结 3 788
长情又很酷
长情又很酷 2021-01-04 04:22

I\'m using DatacontractSerializer to serialize my domainModel into a xml file. I\'m getting output like below.



        
3条回答
  •  礼貌的吻别
    2021-01-04 05:03

    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, "");
    

提交回复
热议问题