Currently, the code below omits null properties during serialization. I want null valued properties in the output xml as empty elements. I searched the web but didn't find anything useful. Any help would be appreciated.
var serializer = new XmlSerializer(application.GetType());
var ms = new MemoryStream();
var writer = new StreamWriter(ms);
serializer.Serialize(writer, application);
return ms;
Sorry, I forgot to mention that I want to avoid attribute decoration.
Set the
XmlElementAttribute.IsNullable
property:https://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlelementattribute.isnullable(v=vs.110).aspx
Can you control the items that have to be serialized?
Using
you can represent it as
<Prop xsi:nil="true" />
You can use also use the following code. The pattern is
ShouldSerialize{PropertyName}
XML