title: C# openxml removal of paragraph
body: <p>I am trying to remove paragraph (I'm using some placeholder text to do generation from docx template-like file) from .docx file using OpenXML, but whenever I remove paragraph it breaks the foreach loop which I'm using to iterate trough.</p>
  
  <pre><code>MainDocumentPart mainpart = doc.MainDocumentPart;
  IEnumerable&lt;OpenXmlElement&gt; elems = mainPart.Document.Body.Descendants();
  
  foreach(OpenXmlElement elem in elems){
      if(elem is Text &amp;&amp; elem.InnerText == "##MY_PLACE_HOLDER##")
      {
          Run run = (Run)elem.Parent;
          Paragraph p = (Paragraph)run.Parent;
          p.RemoveAllChildren();
          p.Remove();
      }
  }
  </code></pre>
  
  <p>This works, removes my place holder and paragraph it is in, <strong>but foreach loop stops iterating</strong>. And I need more things to do in my foreach loop. </p>
  
  <p>Is this <em>ok</em> way to remove paragraph in C# using OpenXML and <strong>why is my foreach loop stopping or how to make it not stop</strong>? Thanks.</p>