i have structure in XML file:
<Employee>
<EmpId>1</EmpId>
<Name>Sam</Name>
<Phone Type="Home">423-555-0124</Phone>
<Phone Type="Work">424-555-0545</Phone>
</Employee>
and class:
public class Phone
{
[XmlAttribute("type")]
public string Type { get; set; }
[XmlText]
public string Value { get; set; }
}
public class Employee
{
[XmlElement("EmpId")]
public int Id { get; set; }
[XmlElement("Name")]
public string Name { get; set; }
[XmlElement("Phone", ElementName = "Phone")]
public Phone phone_home { get; set; }
[XmlElement("Phone2", ElementName = "Phone")]
public Phone phone_work { get; set; }
public Employee() { }
public Employee(string home, string work)
{
phone_home = new Phone()
{
Type = "home",
Value = home
};
phone_work = new Phone()
{
Type = "work",
Value = work
};
}
public static List<Employee> SampleData()
{
return new List<Employee>()
{
new Employee("h1","w1"){
Id = 1,
Name = "pierwszy",
},
new Employee("h2","w2"){
Id = 2,
Name = "drugi",
}
};
}
}
but my problem is that i can't add Two XmlElement with names "Phone". When i try to compile it then i have exception about two same name of XmlElement (repeat: Phone). How can i resolve it?