Remove empty xmlns created by serializer

前端 未结 3 897
故里飘歌
故里飘歌 2021-01-03 05:00

I have an object generated by an \"Add service reference...\" operation and I am manually serializing it with a generic serializer I wrote.

My problem is that the da

3条回答
  •  灰色年华
    2021-01-03 05:20

    If you have control over the serializer you can always add a null namespace to ensure the xmlns is omitted from the output XML. For instance:

    var serializer = new XmlSerializer(target.GetType()); 
    var ns = new XmlSerializerNamespaces(); 
    ns.Add("",""); 
    serializer.Serialize(xmlWriter, target, ns); 
    

    Best regards,

提交回复
热议问题