title: How to Serialize C# Class with class name as root element
body: <p>I have the following C# class</p>
  
  <pre><code>[XmlRoot("Customer")]
  public class MyClass
  {
      [XmlElement("CustId")]
      public int Id {get;set;}
  
      [XmlElement("CustName")]
      public string Name {get;set;}
  }
  </code></pre>
  
  <p>I then use the following function serialise the class object to Xml</p>
  
  <pre><code> public static XmlDocument SerializeObjectToXML(object obj, string sElementName)
   {
      XmlSerializer serializer = 
            new XmlSerializer(obj.GetType(), new XmlRootAttribute("Response"));
  
      using (MemoryStream ms = new MemoryStream())
      {
         XmlDocument xmlDoc = new XmlDocument();
         serializer.Serialize(ms, obj);
         ms.Position = 0;
         xmlDoc.Load(ms);
      }
  }
  </code></pre>
  
  <p>My current output to XML is like;</p>
  
  <pre><code>&lt;Response&gt;
    &lt;CustId&gt;&lt;/CustId&gt;
    &lt;CustName&gt;&lt;/CustName&gt;
  &lt;/Response&gt;
  </code></pre>
  
  <p>But how can I get the response to look like;</p>
  
  <pre><code>&lt;Response&gt;
    &lt;Customer&gt;
       &lt;CustId&gt;&lt;/CustId&gt;
       &lt;CustName&gt;&lt;/CustName&gt;
    &lt;/Customer&gt;
  &lt;/Response&gt;
  </code></pre>