I have a class that I want to serialize
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://xyz.com/schema")]
public class Customer
{
[System.Xml.Serialization.XmlElementAttribute(Order = 0)]
public int Id { get; set; }
[System.Xml.Serialization.XmlElementAttribute(Order = 1)]
public string Name { get; set; }
[System.Xml.Serialization.XmlElementAttribute(Order = 2)]
public string Url{ get; set; }
[System.Xml.Serialization.XmlElementAttribute(Order = 3)]
public string Count { get; set; }
}
When deserializing if Url is null then the out XML does not contain Url Node.
How can mark it as a required field so that Url node gets created everytime?
The
IsNullableattribute should do it.If its set to true, it should generate the tag (According to MSDN).