code: protected static Document createDocumentImpl(
          String name, String namespaceURI, boolean enableExternalEntities,
          boolean isNamespaceAware)
          throws ParserConfigurationException, FactoryConfigurationError
      {
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          factory.setNamespaceAware(isNamespaceAware);
          enableOrDisableExternalEntityParsing(factory, enableExternalEntities);
          DocumentBuilder builder = factory.newDocumentBuilder();
          Document document = builder.newDocument();
          Element rootElement = null;
          if (namespaceURI != null && namespaceURI.length() > 0) {
              rootElement = document.createElementNS(namespaceURI, name);
          } else {
              rootElement = document.createElement(name);
          }
          document.appendChild(rootElement);
          return document;
      }
docs: Construct an XML Document with a default namespace with the given
  root element.
  
  @param name
  the name of the document's root element.
  @param namespaceURI
  default namespace URI for document, ignored if null or empty.
  @param enableExternalEntities
  enable external entities; beware of XML External Entity (XXE) injection.
  @param isNamespaceAware
  enable or disable namespace awareness in the underlying
  {@link DocumentBuilderFactory}
  @return
  an XML Document.
  
  @throws FactoryConfigurationError
  @throws ParserConfigurationException