Prevent self closing tags in XmlSerializer when no data is present

后端 未结 5 937
孤街浪徒
孤街浪徒 2020-12-10 12:53

When I serialize the value : If there is no value present in for data then it\'s coming like below format.

  
        Acknowledged b         


        
5条回答
  •  有刺的猬
    2020-12-10 13:55

    In principal, armen.shimoon's answer worked for me. But if you want your XML output pretty printed without having to use XmlWriterSettings and an additional Stream object (as stated in the comments), you can simply set the Formatting in the constructor of your XmlTextWriter class.

    public MyXmlTextWriter(string filename) : base(filename, Encoding.UTF8)
    {
        this.Formatting = Formatting.Indented;
    }
    

    (Would have posted this as a comment but am not allowed yet ;-))

提交回复
热议问题