Creating a Theader

Creating a Theader

Hello,

I'm creating a table dynamically from a xml using the following code

  1. function showData() {
  2. $.ajax({
  3. type:"GET",
  4. url:"test1.xml",
  5. dataType:"xml",
  6. success: function(xml){
  7. var fila = $(xml).find("Row");
  8. var tabla = $("<table />");
  9. tabla[0].border = "1";
  10. var row = $(tabla[0].insertRow(-1));
  11. fila.eq(0).children().each(function() {
  12. var headerCell = $("<th />");
  13. headerCell.html(this.nodeName);
  14. row.append(headerCell);
  15. });
  16. $(fila).each(function() {
  17. row = $(tabla[0].insertRow(-1));
  18. $(this).children().each(function() {
  19. var cell = $("<td />");
  20. cell.html($(this).text());
  21. row.append(cell);
  22. });
  23. });
  24. var dvTable = $("#dvTable");
  25. dvTable.html("");
  26. dvTable.append(tabla);
  27. }
  28. })
  29. }
It creates the table as follow

<table>
      <tbody>
            <tr>
                  <th>...</th>
                  ....
            </tr>
            <tr>
                  <td...</td>
                   ...
            <t/tr>
            ...
      </tbody>
</table>

How can I make it so that it creates the THEAD tag before the TBODY and add the TH columns inside the THEAD??

Any help would be greatly appreciated. 

Thanks