title: How to for the XML using XDocument class from the below classes
body: <p>I have two classes as</p>
  
  <pre><code>class WarningClass
  {
          public string SqlEyeWarning { get; set; }
          public string FileName { get; set; }
  }
  
  class RemarkClass
  {
          public string SqlEyeRamark { get; set; }
          public string FileName { get; set; }
  }
  </code></pre>
  
  <p>They are populated as under</p>
  
  <pre><code>List&lt;WarningClass&gt; lstWarningClass = new List&lt;WarningClass&gt;();
  lstWarningClass.Add(new WarningClass { FileName = "a.sql", SqlEyeWarning = "SD001: Set QuotedIdentifier ON statement is missing" });
  lstWarningClass.Add(new WarningClass { FileName = "b.sql", SqlEyeWarning = "SD001: Set QuotedIdentifier ON statement is missing" });
  lstWarningClass.Add(new WarningClass { FileName = "c.sql", SqlEyeWarning = "SD009: Missing or order mismatch of Grant statement" });
  lstWarningClass.Add(new WarningClass { FileName = "a.sql", SqlEyeWarning = "SD009: Missing or order mismatch of Grant statement" });
  lstWarningClass.Add(new WarningClass { FileName = "d.sql", SqlEyeWarning = "SD004: Check for existence object then Drop statement before create statement" });
  
  
  
  List&lt;RemarkClass&gt; lstRemarkClass = new List&lt;RemarkClass&gt;();
  lstRemarkClass.Add(new RemarkClass { FileName = "a.sql", SqlEyeRamark = "SD010: Set AnsiiNullsOn ON statement is missing" });
  lstRemarkClass.Add(new RemarkClass { FileName = "b.sql", SqlEyeRamark = "SD002: Order mismatch or it should be ON." });
  lstRemarkClass.Add(new RemarkClass { FileName = "c.sql", SqlEyeRamark = "SD002: Order mismatch or it should be ON." });
  </code></pre>
  
  <p>The desired output will be</p>
  
  <pre><code>&lt;ScriptFileNames&gt;
      &lt;SqlEye&gt;
          &lt;SqlEyeWarnings Name="Set QuotedIdentifier ON statement is missing"&gt;
              &lt;File Name="a.sql" /&gt;
              &lt;File Name="b.sql" /&gt;
          &lt;/SqlEyeWarnings&gt;
          &lt;SqlEyeWarnings Name="SD009: Missing or order mismatch of Grant statement"&gt;
              &lt;File Name="a.sql" /&gt;
              &lt;File Name="c.sql" /&gt;
          &lt;/SqlEyeWarnings&gt;
          &lt;SqlEyeWarnings Name="SD004: Check for existence object then Drop statement before create statement"&gt;
              &lt;File Name="d.sql" /&gt;           
          &lt;/SqlEyeWarnings&gt;
  
          &lt;SqlEyeRemarks Name="SD010: Set AnsiiNullsOn ON statement is missing"&gt;
              &lt;File Name="a.sql" /&gt;           
          &lt;/SqlEyeRemarks&gt;
          &lt;SqlEyeRemarks Name="SD002: Order mismatch or it should be ON."&gt;
              &lt;File Name="b.sql" /&gt;   
              &lt;File Name="c.sql" /&gt;
          &lt;/SqlEyeRemarks&gt;
      &lt;/SqlEye&gt;
  &lt;/ScriptFileNames&gt;
  </code></pre>