code: public static Document toDocument(Source s) {
          Document d = tryExtractDocFromDOMSource(s);
          return d != null ? d 
              : toDocument(s, DocumentBuilderFactoryConfigurer.Default.configure(DocumentBuilderFactory.newInstance()));
      }
docs: Creates a DOM Document from a TraX Source.
  
  <p>If the source is a {@link DOMSource} holding a Document
  Node, this one will be returned.  Otherwise {@link
  #toInputSource} and a namespace aware DocumentBuilder (created
  by the default DocumentBuilderFactory) will be used to read the
  source.  This may involve an XSLT identity transform in
  toInputSource.</p>