title: Unable to save changes to xml file
body: <p>As a learning exercise I'm building a simple Server IP storage and ping monitor application. The application reads a list of servers/hosts from the xml file and displays them to the user and allows them the ability to ping them to check their online status.</p>
  
  <p>The read and ping functionality works fine but when writing code to add an additional server instance the code won't save the new element to the xml file.</p>
  
  <p>Here's the basic XML structure in <code>serverlist.xml</code>: </p>
  
  <pre><code>&lt;servers&gt;
    &lt;server name="Operations"&gt;
        &lt;hostname&gt;Operations&lt;/hostname&gt;
        &lt;hostaddress&gt;address&lt;/hostaddress&gt;
    &lt;/server&gt;
    &lt;server name="Development"&gt;
        &lt;hostname&gt;development&lt;/hostname&gt;
        &lt;hostaddress&gt;address&lt;/hostaddress&gt;
    &lt;/server&gt;
  &lt;/servers&gt;
  </code></pre>
  
  <p>And here is the code I've used to add a new <code>server</code> element:</p>
  
  <pre><code>private void btnAdd_Click(object sender, EventArgs e)
          {
              XDocument xDocument = new XDocument();
              try
              {
                  if (txtHostName.Text == "" || txtHostAddress.Text == "")
                  {
                      MessageBox.Show("Please complete the fields shown!", "Complete form", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                  }
                  else
                  {
                      // Add element to XML
                      if (File.Exists("serverlist.xml"))
                      {
                          xDocument = XDocument.Load("serverlist.xml");
                      }
                      else
                      {
                          MessageBox.Show("No XML available!", "Error", MessageBoxButtons.OK);
                      }
  
                      XElement newServer = new XElement("server", txtServerName.Text,
                              new XElement("hostname", txtHostName.Text),
                              new XElement("hostaddress", txtHostAddress.Text));
  
                      xDocument.Root.Add(newServer);
  
  
                      xDocument.Save("Serverlist.xml");
                      MessageBox.Show("Server Added!", "Server Added", MessageBoxButtons.OK, MessageBoxIcon.Information);
                  }
  
              }
  </code></pre>
  
  <p>I'm not seeing any errors or the catch clauses, the element is just not being saved to the XML. This is probably a very simple and silly thing, but I've done a lot of googling(other search engines are available!) and research into XML functions but I can't seem to see what I've missed.</p>