title: Serialize custom object to XML
body: <p>I'm trying to create a class which I can serialize to produce the following XML:</p>
  
  <pre><code>&lt;chart palette='1'&gt;
    &lt;categories&gt;
      &lt;category label='2001' /&gt;
      &lt;category label='2002' /&gt;
  </code></pre>
  
  <p>..etc</p>
  
  <p>I have a class which look something like this:</p>
  
  <pre><code>[XmlRoot("chart")]
  public class Chart
  {        
      [XmlAttributeAttribute("palette")]
      public string Palette;
  
      [XmlElement("categories")]
      public List&lt;Category&gt; Categories = new List&lt;Category&gt;();
  }
  
  [XmlRoot("category")]
  public class Category
  {
      [XmlAttributeAttribute("label")]
      public string Label;
  }
  </code></pre>
  
  <p>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:</p>
  
  <pre><code> &lt;chart palette="2"&gt;
    &lt;categories label="2002" /&gt; 
   &lt;/chart&gt;
  </code></pre>
  
  <p>How can I get the XML structure I want?</p>