title: Checking for Existing XML Element Content and Replacing It
body: <p>I have a c# app that writes to XML using the following code:</p>
  
  <pre><code>     //Write last compliant elements to state XML if allCompliant bool == true
          if (allCompliant == true)
          {
              if (File.Exists(MainEntry.thirdPartyStateXMLPath))
              {
                  XDocument doc = XDocument.Load(MainEntry.thirdPartyStateXMLPath);
  
                  DateTime localCurrentTime = DateTime.Now;
                  DateTime utcCurrentTime = DateTime.UtcNow;
  
                  XElement root = new XElement("Compliance_Status");
  
                  root.Add(new XElement("Last_Known_Compliant_UTC", utcCurrentTime));
                  root.Add(new XElement("Last_Known_Compliant_LocalTime", localCurrentTime.ToString()));
                  doc.Element("Compliance_Items").Add(root);
                  doc.Save(MainEntry.thirdPartyStateXMLPath);
  
              }
  
          }
  </code></pre>
  
  <p>That renders the following XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Compliance_Items&gt;
    &lt;Compliance_Status&gt;
      &lt;Last_Known_Compliant_UTC&gt;2014-04-03T23:22:31.507088Z&lt;/Last_Known_Compliant_UTC&gt;
      &lt;Last_Known_Compliant_LocalTime&gt;4/3/2014 4:22:31 PM&lt;/Last_Known_Compliant_LocalTime&gt;
    &lt;/Compliance_Status&gt;
  &lt;/Compliance_Items&gt;
  </code></pre>
  
  <p>This code generates the *Last_Known_Compliant_UTC* and *Last_Known_Compliant_LocalTime* elements and values. On subsequent runs of the code I want it to only replace the values of the existing elements, but as written now the following is re-created each time and keeps stacking in the XML:</p>
  
  <pre><code>&lt;Compliance_Status&gt;
       &lt;Last_Known_Compliant_UTC&gt;2014-04-03T23:22:31.507088Z&lt;/Last_Known_Compliant_UTC&gt;
       &lt;Last_Known_Compliant_LocalTime&gt;4/3/2014 4:22:31 PM&lt;/Last_Known_Compliant_LocalTime&gt;
  &lt;/Compliance_Status&gt;
  </code></pre>
  
  <p>How can I achieve the desired effect?</p>