title: Read and Write XML in C# using Linq
body: <p>I want to read and edit the xml file through code. How can I achieve this using XML and Linq? 
  Please help, my xml coding skills are not good. </p>
  
  <p>I want to get the <strong>Entity</strong> with <strong>Name</strong> 'new_test' and read/edit the <strong>RibbonDiffXml</strong> content in that node. </p>
  
  <p>Example XML: </p>
  
  <pre><code>&lt;ImportExportXml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;Entities&gt;
  &lt;Entity&gt;
    &lt;Name LocalizedName="test" OriginalName="test"&gt;new_test&lt;/Name&gt;
    &lt;EntityInfo&gt;...&lt;/EntityInfo&gt;
    ..
    &lt;RibbonDiffXml&gt;..&lt;/RibbonDiffXml&gt;
    ..
  &lt;/Entity&gt;
  &lt;Entity&gt;
    &lt;Name LocalizedName="Account" OriginalName="Account"&gt;account&lt;/Name&gt;
    &lt;EntityInfo&gt;..&lt;/EntityInfo&gt;
    ... 
  &lt;/Entity&gt;
  &lt;/Entities&gt;
  &lt;/ImportExportXml&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>string xml = @"&lt;CustomActions&gt;
                        &lt;CustomAction Id='MsCrm.deal.Form.Clone.CustomAction' Location='Mscrm.Form.deal.MainTab.Save.Controls._children' Sequence='46'&gt;
                          &lt;CommandUIDefinition&gt;
                            &lt;Button Alt='$LocLabels:MsCrm.deal.Form.Clone.Alt' Command='MsCrm.deal.CloneCommand' Id='MsCrm.deal.Form.Clone' Image32by32='$webresource:new_/image/clone32.png' Image16by16='$webresource:new_/image/clone16.png' LabelText='$LocLabels:MsCrm.deal.Form.Clone.LabelText' Sequence='46' TemplateAlias='o1' ToolTipTitle='$LocLabels:MsCrm.deal.Form.Clone.ToolTipTitle' ToolTipDescription='$LocLabels:MsCrm.deal.Form.Clone.ToolTipDescription' /&gt;
                          &lt;/CommandUIDefinition&gt;
                        &lt;/CustomAction&gt;
                      &lt;/CustomActions&gt;";  
  
  
  var ribbon = from entity in document.Root.Element("Entities").Elements()
                           where entity.Element("Name") != null &amp;&amp; entity.Element("Name").Value == entityName
                           select entity.Element("RibbonDiffXml");
  
  
              var action = ribbon.Elements("CustomActions").ToList();
  
              action.Add(XElement.Parse(xml));
  
              document.Save(filePath);
  </code></pre>
  
  <p>I have tried something like this and it doesn't save my changes to the file. However if I use action.Remove() the changes get saved OK. what I am doing wrong ? how can i add elements to the RibbonDiffXml element and save?</p>
  
  <p><img src="https://i.stack.imgur.com/aLYUy.png" alt="xml"></p>