Here you can find the source of getDocumentFromString(String xml)
public static Document getDocumentFromString(String xml) throws ParserConfigurationException, SAXException, IOException
//package com.java2s; //License from project: Open Source 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 getDocumentFromString(String xml) throws ParserConfigurationException, SAXException, IOException { InputSource source = new InputSource(new StringReader(xml)); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setIgnoringElementContentWhitespace(true); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.parse(source); document.normalize();//from w w w.ja va 2 s . c o m return document; } }