Java tutorial
//package com.java2s; import java.io.ByteArrayInputStream; import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.xml.sax.SAXException; public class Main { /** * @param xml * @return * @throws ParserConfigurationException * @throws SAXException * @throws IOException */ public static Document createDoc(String xml) throws ParserConfigurationException, SAXException, IOException { return createDoc(xml, "UTF-8"); } public static Document createDoc(String xml, String encoding) throws ParserConfigurationException, SAXException, IOException { ByteArrayInputStream in = new ByteArrayInputStream(xml.getBytes(encoding)); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(in); return doc; } }