Here you can find the source of createDocumentFromXml(String input)
public static Document createDocumentFromXml(String input) throws ParserConfigurationException, SAXException, IOException
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Document; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.io.StringReader; public class Main { public static Document createDocumentFromXml(String input) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); StringReader stringReader = new StringReader(input); InputSource inputSource = new InputSource(stringReader); return documentBuilder.parse(inputSource); }//from w w w . j ava 2 s. co m }