title: Using F# to search for an element and then adding sibling node
body: <p>Am trying to use F#, for one of the utility jobs that I need to run.</p>
  
  <p>From a directory containing xml config files, I want to identify all the files that contain a particular node with an attribute being looked up and on finding a match, I would like to insert an sibling node in the same file.
  I have written the snippet to identify all the files and now I have a sequence of files which I want to iterate and search for the attribute and append if necessary.</p>
  
  <pre><code>open System.Xml.Linq
  
  let byElementName elementToSearch = XName.Get(elementToSearch)
  
  let xmlDoc = XDocument.Load(@"C:\\Some.xml")
  xmlDoc.Descendants &lt;| byElementName "Elem"
  |&gt; Seq.collect(fun(riskElem) -&gt; riskElem.Attributes &lt;| byElementName "type" )
  |&gt; Seq.filter(fun(pvAttrib) -&gt; pvAttrib.Value = "abc")
  |&gt; Seq.map(fun(pvAttrib) -&gt; pvAttrib.Parent)
  |&gt; Seq.iter(printfn "%A")
  </code></pre>
  
  <p><strong>What I want to do is instead of the last printf, add another node of the type <code>"Elem"</code> with the <code>type = "abc2"</code></strong></p>
  
  
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;Product name="Node" inheritsfrom="Base"&gt;
        &lt;SupportedElems&gt;
          &lt;Elem type="abc" methodology="abcmeth" /&gt;
          &lt;Elem type="def" methodology="defmeth" /&gt;
  &lt;/SupportedElems&gt;
  &lt;/Product&gt;
  </code></pre>
  
  <p>Result XML:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Product name="Node" inheritsfrom="Base"&gt;
    &lt;SupportedElems&gt;
      &lt;Elem type="abc" methodology="abcmeth" /&gt;
      &lt;Elem type="abc2" methodology="abcmeth" /&gt; &lt;!-- NEW ROW TO BE ADDED HERE --&gt;
      &lt;Elem type="def" methodology="defmeth" /&gt;
  </code></pre>
  
  <p>
  </p>