Create DOM Document out of string
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; public class Main { public static Document load(String xml) throws Exception { DocumentBuilder builder = getDocumentBuilder(); Document document = builder.parse(new InputSource(new StringReader(xml))); return document; } public static DocumentBuilder getDocumentBuilder() throws ParserConfigurationException { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setNamespaceAware(true); DocumentBuilder builder = builderFactory.newDocumentBuilder(); return builder; } }