title: How to specify an XmlElement at a different level using XmlSerializer?
body: <p>I have a class which I want to serialize to xml. I want to move one of the properties down a level in the generated xml (an element within an element) <strong>without changing the structure of the class</strong>.  Is it possible to do this using XmlSerializer?</p>
  
  <p>An example:</p>
  
  <p>Generated xml:</p>
  
  <pre><code>&lt;Person&gt;
      &lt;firstname xmlns=\"http://myschema.com\"&gt;John&lt;/firstname&gt;
      &lt;postcode xmlns=\"http://myschema.com\"&gt;N1 0XE&lt;/postcode&gt;
  &lt;/Person&gt;
  </code></pre>
  
  <p>Desired xml:</p>
  
  <pre><code>&lt;Person&gt;
      &lt;firstname xmlns=\"http://myschema.com\"&gt;John&lt;/firstname&gt;
      &lt;address&gt;
          &lt;postcode xmlns=\"http://myschema.com\"&gt;N1 0XE&lt;/postcode&gt;
      &lt;/address&gt;
  &lt;/Person&gt;
  </code></pre>
  
  <p>The code:</p>
  
  <pre><code>[Serializable]
  [XmlType(Namespace = "http://myschema.com")]
  public class Person
  {
      [XmlElement("firstname")]
      public string FirstName { get; set; }
  
      [XmlElement("postcode")]
      public string Postcode { get; set; }
  }
  </code></pre>
  
  <p>Serializer:</p>
  
  <pre><code>var xmlSerializer = new XmlSerializer(typeof(Person));
  var stringWriter = new StringWriter();
  var xmlWriter = XmlWriter.Create(stringWriter);
  
  xmlSerializer.Serialize(xmlWriter, person);
  </code></pre>