Here you can find the source of getDocumentFromString(String xml)
public static Document getDocumentFromString(String xml)
//package com.java2s; //License from project: Open Source License import java.io.*; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.xml.sax.*; import org.w3c.dom.Document; public class Main { public static Document getDocumentFromString(String xml) { Document retVal = null;/*from w w w .j a v a2 s. c o m*/ try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); retVal = db.parse(getInputSourceFromString(xml)); } catch (Exception ex) { ex.printStackTrace(); } return retVal; } /** * Forms an <code>InputSource</code> for parsing XML documents * from a string. Returns <code>null</code> if any of the exceptions * are thrown. * * @param xml String with the XML document. * @return An <code>InputSource</code> representation. */ public static InputSource getInputSourceFromString(String xml) { InputSource retVal = null; try { retVal = new InputSource(new StringReader(xml)); } catch (Exception ex) { } return retVal; } }