1
下午好,XML反序列化不反序列化元素
我有以下類
public class MaintenanceBundle
{
[XmlAttribute(AttributeName = "Required")]
public string Required { get; set; }
[XmlAttribute(AttributeName = "ID")]
public string Id { get; set; }
[XmlElement(ElementName = "Title")]
public string Title { get; set; }
[XmlElement(ElementName = "MntReason")]
public MaintenanceReason Reason { get; set; }
[XmlElement(ElementName = "Tasks")]
public MaintenanceBundleCollection Tasks { get; set; }
}
public class MaintenanceBundleCollection
{
[XmlElement(ElementName = "Task")]
public List<MaintenanceBundleTask> Tasks { get; set; }
}
public class MaintenanceReason
{
[XmlAttribute(AttributeName = "Every")]
public string Every { get; set; }
[XmlElement(ElementName = "Mileage", IsNullable = true)]
public int? Mileage { get; set; }
[XmlElement(ElementName = "Time", IsNullable = true)]
public TimeInterval TimeInterval { get; set; }
}
我試圖反序列化這個XML來使用這些類的對象。這裏是XML
<MntBundle Required="Yes" ID="S08870641702009101200000">
<Title>DIRT OR DUSTY ROADS - 5000 MILES/6 MONTHS</Title>
<MntReason Every="No">
<Mileage Unit="MILES">5000</Mileage>
</MntReason>
<Tasks>
<Task ID="4-2" />
<Task ID="4-3">
<NMVCQualifier>Drive Shaft Boots</NMVCQualifier>
<MVCQualifiers>
<Qualifier Name="Drive Type">4WD</Qualifier>
</MVCQualifiers>
</Task>
<Task ID="4-1" />
<Task ID="4-4" />
<Task ID="5-1">
<MVCQualifiers>
<Qualifier Name="Drive Type">4WD</Qualifier>
</MVCQualifiers>
</Task>
<Task ID="6-1" />
<Task ID="7-1" />
</Tasks>
</MntBundle>
出於某種原因,我無法獲得MntReason元素內的Mileage元素。它不斷返回爲空。任何想法我做錯了什麼?所有其他元素似乎正確地反序列化。我從我的帖子中排除了不相關的課程。如果任何人有任何指示我如何能夠正確地檢索這個值,我很樂意聽到它。非常感謝您的幫助。
乾杯,
〜在聖地亞哥
您的里程元素很複雜(它有一個`單元屬性) - 可能就是這樣。 – Oded 2011-02-09 22:40:27