code: public static void normalizeHTMLTree(Document doc)
      {
          //normalize tables
          NodeList tables = doc.getElementsByTagName("table");
          for (int i = 0; i < tables.getLength(); i++)
          {
              Vector<Node> nodes = new Vector<Node>();
              recursiveFindBadNodesInTable(tables.item(i), null, nodes);
              for (Node n : nodes)
              {
                  moveSubtreeBefore(n, tables.item(i));
              }
          }
      }
docs: Provides a cleanup of a HTML DOM tree according to the HTML syntax restrictions.
  Currently, following actions are implemented:
  <ul>
  <li>Table cleanup
  <ul>
  <li>elements that are not acceptable witin a table are moved before the table</li>
  </ul>
  </li>
  </ul>
  @param doc the processed DOM Document.