I am using the XmlSerializer and have the following property in a class
public string Data { get; set; }
which I need to be output exactly like so
<Data />
How would I go about achieving this?
I was recently doing this and there is an alternative way to do it, that seems a bit simpler. You just need to initialise the value of the property to an empty string then it will create an empty tag as you required;
Data = string.Empty;
The solution to this was to create a PropertyNameSpecified
property that the serializer uses to determine whether to serialize the property or not. For example:
public string Data { get; set; } [XmlIgnore] public bool DataSpecified { get { return !String.IsNullOrEmpty(Data); } set { return; } //The serializer requires a setter }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With