title: Reorder html elements in a string using C#
body: <p>I have a string of html returning from a serivce. I need to update this html server side (Using .Net) and reorder some of the elements around before sending it to the client. As a simple example lets say I have an html string like below. If the string is  a table like below. How can I manipulate it to put the last name <code>&lt;th&gt;</code> and <code>&lt;td&gt;</code> into it's own <code>&lt;tr&gt;</code>. The html would be much larger and more complex but for one section of it the below illustrate how I would need to change it. Just using string replace hasn't worked well due to the complexity of the actual HTML.</p>
  
  <p><strong>Initial String</strong> </p>
  
  <pre><code>   "&lt;table&gt;
       &lt;tbody&gt;
        &lt;tr&gt;
          &lt;th&gt;First name&lt;/th&gt;
          &lt;td&gt;some first name&lt;/td&gt;
          &lt;th&gt;Last name&lt;/th&gt;
          &lt;td&gt;some last name&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;blah&lt;/td&gt;
          &lt;td&gt;blah blah&lt;/td&gt;
        &lt;/tr&gt;
       &lt;/tbody&gt;
      &lt;/table&gt;
      "
  </code></pre>
  
  <p><strong>After Modification</strong></p>
  
  <pre><code>   "&lt;table&gt;
       &lt;tbody&gt;
        &lt;tr&gt;
          &lt;th&gt;First name&lt;/th&gt;
          &lt;td&gt;some first name&lt;/td&gt;
        &lt;/tr&gt;
          &lt;th&gt;Last name&lt;/th&gt;
          &lt;td&gt;some last name&lt;/td&gt;
        &lt;tr&gt;
          &lt;th&gt;blah&lt;/td&gt;
          &lt;td&gt;blah blah&lt;/td&gt;
        &lt;/tr&gt;
       &lt;/tbody&gt;
      &lt;/table&gt;
      "
  </code></pre>