我有以下 XML 需要反序列化为 C# 对象。除了有时为空的日期元素外,所有元素都有效。
<?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>
Run Code Online (Sandbox Code Playgroud)
模型类定义为:
[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 …Run Code Online (Sandbox Code Playgroud)