I'm trying to create a class which I can serialize to produce the following XML:
<chart palette='1'>
<categories>
<category label='2001' />
<category label='2002' />
..etc
I have a class which look something like this:
[XmlRoot("chart")]
public class Chart
{
[XmlAttributeAttribute("palette")]
public string Palette;
[XmlElement("categories")]
public List<Category> Categories = new List<Category>();
}
[XmlRoot("category")]
public class Category
{
[XmlAttributeAttribute("label")]
public string Label;
}
However, this does not produce the desired chart->categories->category@label structure. The XmlRoot on the Category class doesn't seem to be used. Here is the output I have from that code:
<chart palette="2">
<categories label="2002" />
</chart>
How can I get the XML structure I want?