下面是我的 XML 文件。
<Employee>
<FirstName>#{FirstName}#</FirstName>
<LastName>#{LastName}#</LastName>
<DOB>#{DOB}#</DOB>
<Address>#{Address}#</Address>
<Transcation>
<Month>#{Month}#</Month>
<Amount>#{Amount}#</Amount>
</Transcation>
<Transcation>
<Month>#{Month}#</Month>
<Amount>#{Amount}#</Amount>
</Transcation>
<Transcation>
<Month>#{Month}#</Month>
<Amount>#{Amount}#</Amount>
</Transcation>
<Transcation>
<Month>#{Month}#</Month>
<Amount>#{Amount}#</Amount>
</Transcation>
我的可序列化类是
[XmlRoot("Employee"), Serializable]
public class Employee
{
[XmlAnyElement]
public List<XmlElement> EmployeeDetails { get; set; }
}
但我想得到这样的东西
在我的 EmployeeDetails 中,我应该只序列化 FirstName、LastName、DOB、Address ......并且我应该在一个单独的类中获取 Transcation 列表,其中包含 Month 和 Amount 作为可序列化的元素。
像这样的东西
[XmlRoot("Employee"), Serializable]
public class Employee
{
[XmlAnyElement]
public List<XmlElement> EmployeeDetails { get; set; }
[XmlElement("Transcation")]
public List<Transcation> Transcations { get; set; }
}
public class Transcation
{
[XmlElement("Month")]
public string Month{ get; set; }
[XmlElement("Amount")]
public string Amount{ get; set; }
}
我怎样才能做到这一点 ?