code: public static Document streamToDOM(InputStream xmlStream,
                                         boolean namespaceAware) {
          try {
              DocumentBuilderFactory dbFact = DocumentBuilderFactory.newInstance();
              dbFact.setNamespaceAware(namespaceAware);
  
              return dbFact.newDocumentBuilder().parse(xmlStream);
          } catch (IOException e) {
              log.warn("I/O error when parsing stream :" + e.getMessage(), e);
          } catch (SAXException e) {
              log.warn("Parse error when parsing stream :" + e.getMessage(), e);
          } catch (ParserConfigurationException e) {
              log.warn("Parser configuration error when parsing XML stream: "
                       + e.getMessage(), e);
          }
          return null;
      }
docs: Parses a XML document from a stream to a DOM or return
  {@code null} on error.
  
  @param xmlStream      a stream containing an XML document.
  @param namespaceAware if {@code true} the constructed DOM will reflect
  the namespaces declared in the XML document
  @return The document in a DOM or {@code null} in case of errors