code: public static Element parseXMLDocument(String xmlDoc) throws IllegalArgumentException {
          // Parse the given XML document returning its root document Element if it parses.
          // Wrap the document payload as an InputSource.
          Reader stringReader = new StringReader(xmlDoc);
          InputSource inputSource = new InputSource(stringReader);
  
          // Parse the document into a DOM tree.
          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
          DocumentBuilder parser = null;
          Document doc = null;
          try {
              parser = dbf.newDocumentBuilder();
              doc = parser.parse(inputSource);
          } catch (Exception ex) {
              // Turn ParserConfigurationException, SAXException, etc. into an IllegalArgumentException
              throw new IllegalArgumentException("Error parsing XML document: " + ex.getMessage());
          }
          return doc.getDocumentElement();
      }
docs: Parse the given XML document, creating a DOM tree whose root Document object is
  returned. An IllegalArgumentException is thrown if the XML is malformed.
  
  @param   xmlDoc      XML document as a String.
  @return              Root document element of the parsed DOM tree.
  @throws IllegalArgumentException  If the XML is malformed.