title: Using C# XML Serializer to produce custom XML format
body: <p>I'm using Visual Studio 2013 and trying to use the C# XML serializer/deserializer to convert variables stored in a class to/from an XML file (something I'm a novice at).   </p>
  
  <p>Given a simple class:</p>
  
  <pre><code>public class TestXML
  {
      public String Label = "Hello";
      public Boolean Enable = true;
      public Int32 PosX = 12;
      public Int32 PosY = 34;
  }
  </code></pre>
  
  <p>by default the serializer produces XML in the form:</p>
  
  <pre><code>&lt;TestXML&gt;
    &lt;Label&gt;Hello&lt;/Label&gt;
    &lt;Enable&gt;true&lt;/Enable&gt;
    &lt;PosX&gt;12&lt;/PosX&gt;
    &lt;PosY&gt;34&lt;/PosY&gt;
  &lt;/TestXML&gt;
  </code></pre>
  
  <p>Unfortunately, however, my project requirements state that the parameters in the XML file must be formatted as:</p>
  
  <pre><code>&lt;TestXML&gt;
    &lt;model&gt;
      &lt;prop name="Label" value="Hello" /&gt;
      &lt;prop name="Enable" value="true" /&gt;
      &lt;prop name="PosX" value="12" /&gt;
      &lt;prop name="PosY" value="34" /&gt;
    &lt;/model&gt;
  &lt;/TestXML&gt;
  </code></pre>
  
  <p>I've been looking at using the <code>XmlAttribute</code> and <code>XmlElement</code> options to control the XML formatting but can't see any way to produce the required format.  Is there any way to make the serializer store variables in this specific format?</p>