Here you can find the source of getDocumentFromString(String xmlString)
public static Document getDocumentFromString(String xmlString) throws Exception
//package com.java2s; import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.xml.sax.InputSource; public class Main { public static Document getDocumentFromString(String xmlString) throws Exception { DocumentBuilderFactory oDocumentBuilderFactory = DocumentBuilderFactory.newInstance(); try {/*w w w . j a v a 2s. co m*/ // Do not load the DTD oDocumentBuilderFactory.setAttribute("http://apache.org/xml/features/nonvalidating/load-external-dtd", Boolean.FALSE); } catch (IllegalArgumentException e) { } DocumentBuilder oDocumentBuilder = oDocumentBuilderFactory.newDocumentBuilder(); InputSource inputSource = new InputSource(new StringReader(xmlString)); return oDocumentBuilder.parse(inputSource); } }