title: Element is added in wrong place and how to add another sub-element?
body: <p>I have following code written:</p>
  
  <pre><code>public static void AddUploadToXML(XDocument xdoc, int id, string fileHash, string fileName)
      {
          var singleUpload = new XElement("upload",
              new XAttribute("backupid", id),
              new XElement("file", fileHash),
              new XAttribute("filename", fileName)
              );
          xdoc.Root.Add(singleUpload);
      }
  </code></pre>
  
  <p>In the effect I want to to get XML like this:</p>
  
  <pre><code>&lt;uploads&gt;
    &lt;upload backupid="3" &gt;
      &lt;file filename=""&gt;&lt;/file&gt;
    &lt;/upload&gt;
  &lt;/uploads&gt;
  </code></pre>
  
  <p>But I finish with something like this:</p>
  
  <pre><code>&lt;uploads&gt;
    &lt;upload backupid="3" filename=""&gt;
      &lt;file&gt;&lt;/file&gt;
    &lt;/upload&gt;
  &lt;/uploads&gt;
  </code></pre>
  
  <p>Another problem is:</p>
  
  <p>1.How to modify that filename attribute in other part of the app (it will be first file element under upload element with given ID),</p>
  
  <p>2.THEN, how to add other file elements, to finish with something like this:</p>
  
  <pre><code>&lt;uploads&gt;
    &lt;upload backupid="3" &gt;
      &lt;file filename="Test.001"&gt;HASHCODE&lt;/file&gt;
      &lt;file filename="Test.002"&gt;HASHCODE2&lt;/file&gt;
      &lt;file filename="Test.003"&gt;HASHCODE3&lt;/file&gt;
    &lt;/upload&gt;
    &lt;upload backupid="4" &gt;
      &lt;file filename="Test2.001"&gt;HASHCODE&lt;/file&gt;
      (...)
    &lt;/upload&gt;
  &lt;/uploads&gt;
  </code></pre>