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
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
}