title: HtmlAgilityPack - removing all nodes in a collection
body: <p>I'm trying to fix this weird nested HTML I get from using <code>contentEditable</code></p>
  
  <pre><code>&lt;span lang=""&gt;
     &lt;p&gt;line one&lt;/p&gt;
     &lt;p&gt;line two&lt;/p&gt;
  &lt;/span&gt;
  </code></pre>
  
  <p>I want to replace each of these <code>span</code> nodes with its children</p>
  
  <pre><code>&lt;p&gt;line one&lt;/p&gt;
  &lt;p&gt;line two&lt;/p&gt;
  </code></pre>
  
  <p>Here's what I tried. </p>
  
  <pre><code>var spans = doc.DocumentNode.Descendants().Where(x =&gt; x.Name == "span" &amp;&amp; x.Attributes["lang"] != null).ToList();
  foreach (var span in spans)
  {
      foreach (var child in span.ChildNodes)
      {
          var ch = doc.CreateElement(child.Name);
          ch.InnerHtml = child.InnerHtml;
          doc.DocumentNode.InsertBefore(ch, span);
      }            
      span.Remove();
  }
  </code></pre>
  
  <p>This throws a <code>System.ArgumentOutOfRangeException</code> with the following message. </p>
  
  <pre><code>Node "&lt;span lang=""&gt;&lt;/span&gt;" was not found in the collection
  </code></pre>
  
  <p>I understand why this is happening. Editing the document voids my collection of <code>span</code> elements. So how do go about doing this? </p>
  
  <p>Also, how do I cope with text which is not contained in a childnode? Suppose I found this element</p>
  
  <pre><code>&lt;span lang=""&gt;
     &lt;p&gt;line one&lt;/p&gt;
     &lt;p&gt;line two&lt;/p&gt;
     line three
  &lt;/span&gt;
  </code></pre>
  
  <p>How do I de-nest that? </p>
  
  <p><strong>PLEASE NOTE:</strong> This is <code>HtmlAgilityPack</code> for <code>WinRT</code>, so <code>SelectSingleNode</code> and all xpath commands are not available to me</p>