Node copy = item.cloneNode(true); cursor.appendChild(copy); cursor = copy;
cursor.appendChild(item); cursor = item;
  protected void handleEndTag(TagElement tag)  {    String name = tag.getHTMLTag().toString();    String nname = cursor.getNodeName();    // Closing the current tag.    if (nname != null && nname.equalsIgnoreCase(name))      {        cursor = cursor.getParentNode();      }    else      {        Node nCursor = cursor.getParentNode();        // Remember the opened nodes.        LinkedList open = new LinkedList();        Node close = cursor;        while (close != null && !close.getNodeName().equalsIgnoreCase(name))          {            if (close != document)              open.addFirst(close);            close = close.getParentNode();          }        if (close == null)          cursor = document;        else          cursor = close.getParentNode();        // Insert the copies of the opened nodes.           Iterator iter = open.iterator();        while (iter.hasNext())          {            Node item = (Node) iter.next();            Node copy = item.cloneNode(true);            cursor.appendChild(copy);            cursor = copy;          }      }  }