title: This document already has a ' DocumentElement ' node
body: <p>I'm adding a new node at the end of a file, but I get a write error:</p>
  
  <blockquote>
    <p>This document already has a 'DocumentElement' node.</p>
  </blockquote>
  
  <p>My code:</p>
  
  <pre><code>XmlDocument doc = new XmlDocument();
  doc.Load(directory);
  XmlNode refElem = doc.LastChild; // Last node
  
  foreach (MoneyEnter myList in list)
  {
      XmlElement entryElement = doc.CreateElement("entry");
      entryElement.SetAttribute("type", myList.TypeAmount);
  
      XmlElement amountElement = doc.CreateElement("amount");
      amountElement.InnerText = Convert.ToString(myList.Amount);
  
      XmlElement dateElement = doc.CreateElement("date");
      dateElement.InnerText = Convert.ToString(myList.Date);
  
      XmlElement descriptionElement = doc.CreateElement("description");
      XmlCDataSection cdataDescription = doc.CreateCDataSection(myList.Description);
      descriptionElement.AppendChild(cdataDescription);
  
      XmlElement categoryElement = doc.CreateElement("category");
      categoryElement.InnerText = myList.Category;
  
      entryElement.AppendChild(amountElement);
      entryElement.AppendChild(dateElement);
      entryElement.AppendChild(descriptionElement);
      entryElement.AppendChild(categoryElement);
      doc.InsertAfter(entryElement, refElem); //add new node in end of file
  }
  doc.Save(directory);
  </code></pre>
  
  <p>My XML file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;entries&gt;
      &lt;entry type="debit"&gt;
          &lt;amount&gt;5&lt;/amount&gt;
          &lt;date&gt;01.01.0001 0:00:00&lt;/date&gt;
          &lt;description&gt;ffvfd&lt;/description&gt;
          &lt;category&gt;fdvfvf&lt;/category&gt;
      &lt;/entry&gt;
      &lt;entry type="debit"&gt;
          &lt;amount&gt;5&lt;/amount&gt;
          &lt;date&gt;01.01.0001 0:00:00&lt;/date&gt;
          &lt;description&gt;fvfv&lt;/description&gt;
          &lt;category&gt;fvfdvfd&lt;/category&gt;
      &lt;/entry&gt;
      &lt;entry type="debit"&gt;
          &lt;amount&gt;5&lt;/amount&gt;
          &lt;date&gt;01.01.0001 0:00:00&lt;/date&gt;
          &lt;description&gt;fv gfv&lt;/description&gt;
          &lt;category&gt;dscdcd&lt;/category&gt;
      &lt;/entry&gt;
      &lt;entry type="debit"&gt;
          &lt;amount&gt;5&lt;/amount&gt;
          &lt;date&gt;01.01.0001 0:00:00&lt;/date&gt;
          &lt;description&gt;vfvfv&lt;/description&gt;
          &lt;category&gt;cfcfc&lt;/category&gt;
      &lt;/entry&gt;
      &lt;entry type="debit"&gt;
          &lt;amount&gt;7&lt;/amount&gt;
          &lt;date&gt;01.01.0001 0:00:00&lt;/date&gt;
          &lt;description&gt;gfbvgv&lt;/description&gt;
          &lt;category&gt;gfbgfb&lt;/category&gt;
      &lt;/entry&gt;
  &lt;/entries&gt;
  </code></pre>