以下是我的XML文件。如何在C#中實現自定義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我應該序列只有名字,姓氏,出生日期,地址, ....我應該在一個單獨的類中包含Month和Amount作爲可序列化元素的Transcation List。
像這樣
[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; }
}
我怎樣才能做到這一點?