我有以下xml结构
<root>
<title>List</title>
<units>Total Units: 79.0</units>
<sesgrps>
<sesgrp>
<classes>
<class>
<subj_area_name>C# language</subj_area_name>
<class_name>C# Class</class_name>
</class>
<class>
<subj_area_name>VB language</subj_area_name>
<class_name>VB Class</class_name>
</class>
<class>
<subj_area_name>F# language</subj_area_name>
<class_name>F# Class</class_name>
</class>
</classes>
</sesgrp>
</sesgrps>
为此,我创建了如下类:
[Serializable]
[XmlRoot("root")]
public class Data
{
[XmlElement("title")]
public string Title { get; set; }
[XmlElement("units")]
public string Units { get; set; }
[XmlArray("sesgrps")]
[XmlArrayItem("sesgrp")]
public List<SessionGroup> SessionGroups { get; set; }
}
[Serializable]
public class SessionGroup
{
[XmlArray("classes")]
[XmlArrayItem("class")]
public List<Class> Classes { get; set; }
}
[Serializable]
public class Class
{
.....................
.....................
}
当我反序列化时,我只得到一个 Class 项目而不是Classes 集合中的 3 个类项目。