Since DOM is a document model, DOM-document may be created directly, without loading from a XML file. Though, in order to create new DOM document we have to use the same DocumentBuilder. After document is created it should be supplied with document (root) element. All the elements a creates via method of class Document:

 import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.*;

 * This sample program shows how to create new document 
 * from stretch using DOM interface.

public class Test {
  public static void main(String[] args) {
    try {
      // first of all we request out 
      // DOM-implementation:
      DocumentBuilderFactory factory = 
      // then we have to create document-loader:
      DocumentBuilder loader = factory.newDocumentBuilder();

      // createing a new DOM-document...
      Document document = loader.newDocument();
      // initially it has no root-element, ... so we create it:
      Element root = document.createElement("purchase-order");
      // we can add an element to a document only once,
      // the following calls will raise exceptions:

      // ... compose the rest document content ...
    } catch (ParserConfigurationException ex) {
      // document-loader cannot be created which,
      // satisfies the configuration requested
    } catch (FactoryConfigurationError ex) {
      // DOM-implementation is not available or 
      // cannot be instantiated:

  private static final void handleError(Throwable ex) {
    // ... handle error here...