Hi,
i am using System.Xml.Serialization;
how can i serialize an empty element output <something /> ?
current, after serialize an empty element, it wont show, only not null element wil be output.
Please advise.
Printable View
Hi,
i am using System.Xml.Serialization;
how can i serialize an empty element output <something /> ?
current, after serialize an empty element, it wont show, only not null element wil be output.
Please advise.
My first question would be, why do you want to serialize something that does not contain any information? Why not just check on the deserialize side and take action if that object and / or variable is null or empty?
You can add an attribute above your property:
<XmlElement(isnullable:=True)>
public string Something;
Quote:
Originally Posted by Phenglai
eg.
<car>
<door>door 1</door>
<door>door 2</door>
<alarm>alarm brand</alarm>
</car>
<car>
<door>door 1</door>
<door>door 2</door>
<alarm/>
</car>
Not every car has alarm but i want to show as an empty tag instead of no tag.