给定以下 XML,我如何使用以下实现将每条记录读入对象列表(记录列表)?
class Record
{
public string Name {get; set;}
public List<Skill> Skills {get; set;}
}
class Skill
{
public string SkillName {get; set;}
public string SkillType {get; set;}
}
xml
<records>
<record>
<name>John</name>
<skills>
<skill>
<skillname>Tennis</skillname>
<skilltype>Sport</skilltype>
</skill>
<skill>
<skillname>Violin</skillname>
<skilltype>Music</skilltype>
</skill>
</skills>
</record>
<record>
<name>Juanita</name>
<skills>
<skill>
<skillname>Football</skillname>
<skilltype>Sport</skilltype>
</skill>
<skill>
<skillname>Pottery</skillname>
<skilltype>Craft</skilltype>
</skill>
</skills>
</record>
</records>
我尝试获取子元素(技能)没有成功。
List<Records> records;
DataSet dstRecords = new DataSet();
dstRecords.ReadXml(file);
foreach (DataRow row in dstRecords.Tables[0].Rows)
{
Record record = new Record
{
Name = Convert.ToString(row["name"]),
Skills = skills
};
records.Add(records);
}