title: OpenXML: Replace <sdt/> element with table in WordprocessingML
body: <p>I'm using the OpenXML SDK to programatically replace some <code>&lt;w:sdt/&gt;</code> elements with chunks of OpenXML (WordProcessingML) markup.</p>
  
  <p>For example, I have a paragraph with these contents:</p>
  
  <pre><code>&lt;w:p&gt;
    &lt;w:run&gt;&lt;w:text&gt; Text before &lt;/w:text&gt;&lt;/w:run&gt;
    &lt;w:sdt&gt;&lt;w:sdtPr&gt; ...&lt;/w:sdtPr&gt;&lt;w:sdtContent&gt;...&lt;/w:sdtContent&gt;&lt;/w:sdt&gt;
    &lt;w:run&gt;&lt;w:text&gt; Text after &lt;/w:text&gt;&lt;/w:run&gt;
  &lt;/w:p&gt;
  </code></pre>
  
  <p>And a table with a structure like this:</p>
  
  <pre><code>&lt;w:tbl&gt;
    &lt;w:tblPr&gt;...&lt;/w:tblPr&gt;
    &lt;w:tblGrid&gt; ... gridCol elements ...&lt;/w:tblGrid&gt;
    &lt;w:tr&gt;
      &lt;w:trPr&gt;...&lt;/w:trPr&gt;
      &lt;w:tc&gt;
     &lt;w:tcPr&gt;...&lt;/w:tcPr&gt;
     &lt;w:p&gt; Cell contents &lt;/w:p&gt;
      &lt;/w:tc&gt;
      &lt;w:tc&gt;
     &lt;w:tcPr&gt;...&lt;/w:tcPr&gt;
     &lt;w:p&gt; Cell contents &lt;/w:p&gt;
      &lt;/w:tc&gt;
    &lt;/w:tr&gt;
   &lt;/w:tbl&gt;
  </code></pre>
  
  <p>Basically I want to replace the <code>&lt;w:sdt/&gt;</code> element in the paragraph with the table markup.
  The problem is that I cannot just replace it because it will create an invalid document (a table with paragraphs inside another paragraph element isn't valid).</p>
  
  <p>The result that I want to get is this:</p>
  
  <pre><code>&lt;w:p&gt;
    &lt;w:run&gt;&lt;w:text&gt; Text before &lt;/w:text&gt;&lt;/w:run&gt;
  &lt;/w:p&gt;
  &lt;w:tbl&gt;
    &lt;w:tblPr&gt;...&lt;/w:tblPr&gt;
    &lt;w:tblGrid&gt; ... gridCol elements ...&lt;/w:tblGrid&gt;
    &lt;w:tr&gt;
      &lt;w:trPr&gt;...&lt;/w:trPr&gt;
      &lt;w:tc&gt;
     &lt;w:tcPr&gt;...&lt;/w:tcPr&gt;
     &lt;w:p&gt; Cell contents &lt;/w:p&gt;
      &lt;/w:tc&gt;
      &lt;w:tc&gt;
     &lt;w:tcPr&gt;...&lt;/w:tcPr&gt;
     &lt;w:p&gt; Cell contents &lt;/w:p&gt;
      &lt;/w:tc&gt;
    &lt;/w:tr&gt;
  &lt;/w:tbl&gt;
  &lt;w:p&gt;
    &lt;w:run&gt;&lt;w:text&gt; Text after &lt;/w:text&gt;&lt;/w:run&gt;
  &lt;/w:p&gt;
  </code></pre>
  
  <p>I was thinking on creating a method that created a new paragraph with the elements before the <code>&lt;w:sdt/&gt;</code> element, and another one with the elements after the sdt element, but it seems like such a method would be error-prone.</p>
  
  <p>Is there a method that can do what I want without having to do it manually (a method that does what Word does when I try to insert a new table inside a text line)?</p>
  
  <p>Any help will be greatly appreciated.</p>