Here you can find the source of stringToDocument(String xmlStr, boolean isValidating)
public static Document stringToDocument(String xmlStr, boolean isValidating) throws SAXException, IOException, ParserConfigurationException
//package com.java2s; //License from project: Mozilla Public License import java.io.IOException; import java.io.StringReader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.xml.sax.InputSource; import org.xml.sax.SAXException; public class Main { public static Document stringToDocument(String xmlStr, boolean isValidating) throws SAXException, IOException, ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(isValidating); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource inputSource = new InputSource(new StringReader(xmlStr)); Document document = builder.parse(inputSource); return document; }//from w w w. j a v a 2 s .c om }