title: Updating Child's Attribute of a XElement (or a Cloned XElement)
body: <p>I have an XML as follows. </p>
  
  <pre><code>&lt;AFConfig&gt;
   &lt;Geographies&gt;
    &lt;Geography id="Place1" description="NicePlace"&gt;
     &lt;MetaData&gt;
      &lt;Services&gt;
       &lt;Service&gt;
       ...
       ...
       &lt;/Service&gt;
      &lt;/Services&gt;
     &lt;/MetaData&gt;
     &lt;Systems&gt;
      &lt;DefaultSystem systemName="SYSONE" server=http"//192.168.0.0" /&gt;
     &lt;/Systems&gt;
    &lt;/Geography&gt;
   &lt;Geographies&gt; 
  &lt;/AFConfig&gt;
  </code></pre>
  
  <p>What I want to do is this. </p>
  
  <ol>
  <li>Clone the element Geography and add it as a Sibling (i.e., Child to Geographies)</li>
  <li>Update "id", "description" with new values
  AND</li>
  <li>update the systemName with new value</li>
  </ol>
  
  <p>My Code. </p>
  
  <pre><code>XDocument xd_Document = XDocument.Load(s_FileName);
  XElement xe_Element = (from xe in xd_Document.XPathSelectElements(s_Element)
                         where xe.Attribute(s_IdAttr).Value == s_Value
                         select xe).SingleOrDefault();
  XElement xe_NewElement = CloneElement(xe_Element)
  foreach(KeyValuePair&lt;string, string&gt; s in d_AttrValue)
      xe_NewElement.Attribute(s.Key).Value = d_AttrValue[s.Key];
  xe_Element.Parent.Add(xe_NewElement);
  xd_Document.Save(s_destFileName);
  </code></pre>
  
  <p>I pass to this method the following parameters
  string s_FileName, string s_destFileName, string s_Element, string s_IdAttr, string s_Value, Dictionary d_AttrValue</p>
  
  <p>With this code, I am able to modify the id and description attributes. </p>
  
  <p>Question: How will I modify the DefaultSystem attribute systemName with a value?</p>
  
  <p>NB: I have the same code for Modification of existing Element sans the Creation of New Element. Again, I run into the same problem. A generic solution would be preferred. </p>