C#C
C#3y ago
4 replies
Deleted User 93w4ls0g

XML Serialization: How to serialize a property with a null value without xsi:nill attribute?

I have a property the following code:

    [Serializable()]
    public class MyClass
    {
 
        [XmlElement(ElementName = "MyProperty")]
        public decimal? MyProperty
        {
            get;
            set;
        }
    }


At the minute, when I serialize it I get:

<MyProperty xsi:nil="true" />


But I want to get this:

<MyProperty />


What is the best way of achieving this? I do not want to do any post-processing such as
myXML.Replace("xsi:nil="true"", "")
Was this page helpful?