Java tutorial
//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 { // 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); } }