title: how to append a xml file in c#?
body: <p>i am adding tracing for audit purposes of a simple process i have built as an .exe and set in the scheduler to run every 10 minutes. i want to have the application output the results into an xml file.  </p>
  
  <p>if the file exists then open and append data to it, if it does not exist i want to create a new xml file that will be persisted and used on next run.</p>
  
  <p>here is my code now, what do i need to add, how do i open the xml file (on c:/file.xml) and use it to append nodes to?</p>
  
  <pre><code>static void Main(string[] args)
  {
      XmlDocument doc = new XmlDocument();
  
      XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);
      doc.AppendChild(dec);// Create the root element
  
      XmlElement root = doc.CreateElement("STATS");
      doc.AppendChild(root);
  
      XmlElement urlNode = doc.CreateElement("keepalive");
      urlNode.SetAttribute("runTime", DateTime.Now.ToString());
  
      try
      {
          WebProxy wp = new WebProxy("http://proxy.ml.com:8083/");
          WebClient w = new WebClient();
          w.Proxy = wp;
  
          if (w.DownloadString("http://wwww.example.com") != "")
              urlNode.SetAttribute("result", "UP");
          else
              urlNode.SetAttribute("result", "DOWN");
      }
      catch
      {
          urlNode.SetAttribute("result", "DOWN");
      }
      finally
      {
          root.AppendChild(urlNode);
          doc.Save("c:/keepAlive.xml");
      }
  }
  </code></pre>