title: XML file creation using XDocument in C#
body: <p>I have a <code>List&lt;string&gt;</code> "sampleList" which contains</p>
  
  <pre><code>Data1
  Data2
  Data3...
  </code></pre>
  
  <p>The file structure is like</p>
  
  <pre><code>&lt;file&gt;
     &lt;name filename="sample"/&gt;
     &lt;date modified ="  "/&gt;
     &lt;info&gt;
       &lt;data value="Data1"/&gt; 
       &lt;data value="Data2"/&gt;
       &lt;data value="Data3"/&gt;
     &lt;/info&gt;
  &lt;/file&gt;
  </code></pre>
  
  <p>I'm currently using XmlDocument to do this. </p>
  
  <p>Example:</p>
  
  <pre><code>List&lt;string&gt; lst;
  XmlDocument XD = new XmlDocument();
  XmlElement root = XD.CreateElement("file");
  XmlElement nm = XD.CreateElement("name");
  nm.SetAttribute("filename", "Sample");
  root.AppendChild(nm);
  XmlElement date = XD.CreateElement("date");
  date.SetAttribute("modified", DateTime.Now.ToString());
  root.AppendChild(date);
  XmlElement info = XD.CreateElement("info");
  for (int i = 0; i &lt; lst.Count; i++) 
  {
      XmlElement da = XD.CreateElement("data");
      da.SetAttribute("value",lst[i]);
      info.AppendChild(da);
  }
  root.AppendChild(info);
  XD.AppendChild(root);
  XD.Save("Sample.xml");
  </code></pre>
  
  <p>How can I create the same XML structure using XDocument?</p>