Java tutorial
//package com.java2s; import java.io.CharArrayReader; import javax.xml.parsers.DocumentBuilder; import org.w3c.dom.Document; import org.xml.sax.InputSource; public class Main { public static Document loadString(String domContent) throws Exception { javax.xml.parsers.DocumentBuilderFactory factory = javax.xml.parsers.DocumentBuilderFactory.newInstance(); factory.setIgnoringComments(false); factory.setIgnoringElementContentWhitespace(false); factory.setValidating(false); factory.setCoalescing(false); DocumentBuilder builder = factory.newDocumentBuilder(); char[] chars = new char[domContent.length()]; domContent.getChars(0, domContent.length(), chars, 0); InputSource is = new InputSource(new CharArrayReader(chars)); return (builder.parse(is)); } }