I am trying to create a class that I can serialize to create the following XML:
<chart palette='1'>
<categories>
<category label='2001' />
<category label='2002' />
.. etc.
I have a class that looks 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 create the desired chart structure chart-> categories-> category @. The XmlRoot in the Category class does not seem to be used. Here is the result I got from this code:
<chart palette="2">
<categories label="2002" />
</chart>
How to get the XML structure I want?
source
share