Here you can find the source of string2Dom(String xml)
public static Document string2Dom(String xml)
//package com.java2s; //License from project: Apache License 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 string2Dom(String xml) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try {//from ww w.j av a2 s . c om dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(string2InputSource(xml)); return doc; } catch (Exception e) { System.out.println("caught exception while parsing: " + e); return null; } } public static InputSource string2InputSource(String xml) { return new InputSource(new StringReader(xml)); } }