title: Generating XML from multiple classes?
body: <p>i have another question on getting my XML serialization neat, which i can't seem to get right. my config file is as follows:</p>
  
  <pre><code>namespace SMCProcessMonitor
  {
  [Serializable()]
  [XmlRoot("Email-Settings")] 
       public class Config
  {     
           [XmlElement("Recipient")]
           public string recipient;
           [XmlElement("Server-port")]
           public int serverport;
           [XmlElement("Username")]
           public string username;
           [XmlElement("Password")]
           public string password;
           [XmlElement("Program")]
           public List&lt;Programs&gt; mPrograms = new List&lt;Programs&gt;();
           public string serialId;
       }
  
       public class Email
      {
  
               public string Recipient
               {
                   get
                   {
                       return SMCProcessMonitor.ConfigManager.mConfigurations.recipient;
                   }
                   set
                   {
                       SMCProcessMonitor.ConfigManager.mConfigurations.recipient = value;
                   }
               }
  
               public int ServerPort
               {
                   get
                   {
                       return SMCProcessMonitor.ConfigManager.mConfigurations.serverport;
                   }
                   set
                   {
                       SMCProcessMonitor.ConfigManager.mConfigurations.serverport = value;
                   }
               }
               public string Username
               {
                   get
                   {
                       return SMCProcessMonitor.ConfigManager.mConfigurations.username;
                   }
                   set
                   {
                       SMCProcessMonitor.ConfigManager.mConfigurations.username = value;
                   }
               }
          public string Password { get; set; }
  
      }
           [Serializable()]
      public class Programs
  {
          [XmlElement("Filename")] public string mFileName { get; set; }
          [XmlElement("Filepath")]public string mFilePath { get; set; }
  }
  
           public class Database
           {
               public string mSerial { get; set; }
           }
           }
  </code></pre>
  
  <p>Ideally what i want to do is have each of these three classes (email settings, database and programs) have their own tags, like so</p>
  
  <pre><code>&lt;Config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"               xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  &lt;email-settings&gt;
    &lt;Recipient&gt;sadh&lt;/Recipient&gt;
    &lt;Server-port&gt;23&lt;/Server-port&gt;
    &lt;Username&gt;lkms&lt;/Username&gt;
    &lt;Password&gt;kmkdvm&lt;/Password&gt;
  &lt;/email-settings&gt;
  &lt;Program&gt;
    &lt;Filename&gt;MerlinAlarm.exe&lt;/Filename&gt;
    &lt;Filepath&gt;D:\Merlin\Initsys\Merlin\Bin\MerlinAlarm.exe&lt;/Filepath&gt;
  &lt;/Program&gt;
  &lt;database-settings&gt;
    &lt;serialId&gt;1&lt;/serialId&gt;
  &lt;/database-settings&gt;
  &lt;/Config&gt;
  </code></pre>
  
  <p>But instead i get something that resembles this:</p>
  
  <pre><code> &lt;Config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
   &lt;Recipient&gt;blah&lt;/Recipient&gt;
   &lt;Server-port&gt;1111&lt;/Server-port&gt;
   &lt;Username&gt;blah&lt;/Username&gt;
   &lt;Password&gt;blah&lt;/Password&gt;
   &lt;Program&gt;
   &lt;Filename&gt;chrome.exe&lt;/Filename&gt;
   &lt;Filepath&gt;
   C:\Users\Shane\AppData\Local\Google\Chrome\Application\chrome.exe
   &lt;/Filepath&gt;
   &lt;/Program&gt;
   &lt;serialId&gt;1234&lt;/serialId&gt;
   &lt;/Config&gt;
  </code></pre>
  
  <p>Sorry to be such a bother, but this is doing my nut in now and im sure there's some fundamental logic i'm missing here..can anyone give me some pointers as to how to get this XML in the format i specified above? 
  Thanks in advance, Shane.</p>
  
  <p>Edit: My serialization class.</p>
  
  <pre><code> namespace SMCProcessMonitor
  {
  public class ShanesXMLserializer
  {
      private string  mFileAndPath;
      public Config   mConfigurations = null;
      public Config mConfigurationsProgram = null;
  
  
  
      public ShanesXMLserializer(string inFileAndPath)
      {
          mFileAndPath    = inFileAndPath;
          mConfigurations = new Config();
  
      }
  
      public bool Write()
      {
          try
          {
              XmlSerializer x = new XmlSerializer(mConfigurations.GetType());
              StreamWriter writer = new StreamWriter(mFileAndPath);
              x.Serialize(writer, mConfigurations);
              writer.Close();
              return true;
          }
          catch (Exception ex)
          {
              MessageBox.Show("Exception found while writing: " + ex.Message);
          };
  
          return false;
      }
  
      public bool Read()
      {
          try
          {
              XmlSerializer x = new XmlSerializer(typeof(Config));
              StreamReader reader = new StreamReader(mFileAndPath);
              mConfigurations = (Config)x.Deserialize(reader);
              reader.Close();
              return true;
          }
          catch (Exception ex)
          {
              MessageBox.Show("Exception found while reading: " + ex.Message);
          };
  
          return false;
      }
  
      public Config GetConfigEmail
      {
          get
          {
              return mConfigurations;
          }
      }
  
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Edit 2:
  My new config file:
  @Craig - I'm using this config file, which is like you said but im still not getting the desired XML, shown after my config class.</p>
  
  <pre><code>           using System;
             using System.Collections.Generic;
             using System.Linq;
             using System.Xml.Serialization;
             using System.Text;
  </code></pre>
  
  <p>namespace SMCProcessMonitor
  {
      [Serializable()]</p>
  
  <pre><code>     public class Config
  {     
  
           public string recipient;
           public int serverport;
           public string username;
           public string password;
           public List&lt;Programs&gt; mPrograms = new List&lt;Programs&gt;();
           public string serialId;
      [XmlElement("email-settings")]
           public Email Email { get; set; }
           public Programs Programs { get; set; }
       [XmlElement("database-settings")]
           public Database Database { get; set; }
  
  
       }
  
       public class Email
      {
           [XmlElement("Recipient")]
           public string Recipient { get; set; }
              [XmlElement("Server-port")]
           public int ServerPort { get; set; }
           [XmlElement("Username")]
           public string Username { get; set; }
           [XmlElement("Password")]
           public string Password { get; set; }
  
      }
           [Serializable()]
      public class Programs
      {
          [XmlElement("Filename")] public string mFileName { get; set; }
          [XmlElement("Filepath")]public string mFilePath { get; set; }
      }
  
      public class Database
      {
          [XmlElement("SerialID")]
          public string mSerial { get; set; }
      }
      }
  </code></pre>
  
  <p>But i am still getting:</p>
  
  <pre><code>  &lt;Config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;recipient&gt;shane&lt;/recipient&gt;
    &lt;serverport&gt;23&lt;/serverport&gt;
    &lt;username&gt;oid&lt;/username&gt;
    &lt;password&gt;jidj&lt;/password&gt;
    &lt;mPrograms/&gt;
    &lt;/Config&gt;
  </code></pre>