code: public static Document stringToDOM(String xmlString,
                                         boolean namespaceAware) {
          try {
              InputSource in = new InputSource();
              in.setCharacterStream(new StringReader(xmlString));
  
              DocumentBuilderFactory dbFact = DocumentBuilderFactory.newInstance();
              dbFact.setNamespaceAware(namespaceAware);
  
              return dbFact.newDocumentBuilder().parse(in);
          } catch (IOException e) {
              log.warn("I/O error when parsing XML :" + e.getMessage() + "\n"
                       + xmlString, e);
          } catch (SAXException e) {
              log.warn("Parse error when parsing XML :" + e.getMessage() + "\n"
                       + xmlString, e);
          } catch (ParserConfigurationException e) {
              log.warn("Parser configuration error when parsing XML :"
                       + e.getMessage() + "\n"
                       + xmlString, e);
          }
          return null;
      }
docs: Parses an XML document from a String to a DOM.
  
  @param xmlString      a String containing an XML document.
  @param namespaceAware if {@code true} the parsed DOM will reflect any
  XML namespaces declared in the document
  @return The document in a DOM or {@code null} on errors.