I have the following XML which needs to be deserialized into C# objects. All the elements work except for date elements which sometimes are empty.
<?xml version="1.0" encoding="utf-8" ?>
<Output xmlns:b="http://webservices.mycompany.com/Order/17.2.0">
<b:RequestedCompletionDate>
<State>Modified</State>
<Action>DateSpecified</Action>
<Date></Date>
</b:RequestedCompletionDate>
</Output>
The model class is defined as:
[System.Xml.Serialization.XmlType(Namespace = "http://webservices.mycompany.com/Order/17.2.0", AnonymousType = true)]
[System.Xml.Serialization.XmlRoot(Namespace = "http://webservices.mycompany.com/Order/17.2.0", IsNullable = false)]
public partial class RequestedCompletionDate
{
private string stateField;
private string actionField;
private DateTime? dateField;
/// <remarks/>
[System.Xml.Serialization.XmlElement(Namespace = "http://webservices.mycompany.com/Framework/17.2.0")]
public string State
{
get
{
return this.stateField;
}
set
{
this.stateField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElement(Namespace = "http://webservices.mycompany.com/Framework/17.2.0")]
public string Action
{
get
{
return this.actionField;
}
set
{
this.actionField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElement(Namespace = "http://webservices.mycompany.com/Framework/17.2.0")]
public DateTime? Date
{
get
{
return this.dateField;
}
set
{
this.dateField = value;
}
}
}
The exception I get is:
"The string '' is not a valid AllXsd value."
It doesn't like passing a null date value to a DateTime property.
How can I deserialize to a DateTime property when the date value is empty?