code: public static void setDocumentElement(final Document document, final Element element) {
          Element documentElement = document.getDocumentElement();
          if (documentElement != null) {
              document.removeChild(documentElement);
          }
          if (element != null) {
              if (element.getOwnerDocument().equals(document)) {
                  document.appendChild(element);
                  return;
              }
              Node node = document.adoptNode(element);
              document.appendChild(node);
          }
      }
docs: Replace the current root element. If element is null, the current root element will be
  removed.
  
  @param document
  @param element