I have a set of large XML files with various sections in them.
As an example file I have mocked this up which serializes and deserializes just fine if I don't have the appended counter of 1, 2, 3... etc.
<?xml version="1.0" encoding="utf-16"?>
<employees xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<category name="TestCategory" baseicon="0" decalicon="0">
<EmployeeList1>
<name type="string">Peter Parker</name>
<age type="number">25</age>
</EmployeeList1>
<EmployeeList2>
<name type="string">J.J. Jameson</name>
<age type="number">57</age>
</EmployeeList2>
</category>
</employees>
However, when I have the incremented elements in the collection I get back no objects in the EmployeeList collection but will get back the overall Employees object.
So all the objects within the EmployeeList elements have the same structure overall although some will have optional fields like, let's say "homeowner".
[XmlRoot(ElementName = "category")]
public class Category
{
[XmlAttribute(AttributeName = "name")]
public string Name;
[XmlAttribute(AttributeName = "baseicon")]
public int Baseicon;
[XmlAttribute(AttributeName = "decalicon")]
public int Decalicon;
[XmlElement]
public List<Employee> EmployeeList { get; set; }
public Category()
{
}
}
And the Employee class looks like this:
[XmlRoot(ElementName = "employees")]
public class Employees
{
[XmlElement(ElementName = "category")]
public Category Category;
public Employees()
{
}
}
[XmlRoot(ElementName = "employee")]
public class Employee
{
[XmlElement(ElementName = "name")]
public Name Name { get; set; }
[XmlElement(ElementName = "age")]
public Age Age { get; set; }
}
Then, of course the follow up is how to serialize a collection of elements with an incremented ID?