Java tutorial
//package com.java2s; 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 stringToDocument(String xml) { Document doc = null; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); // Turn on validation, and turn off namespaces factory.setValidating(false); factory.setNamespaceAware(false); try { DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.parse(new InputSource(new StringReader(xml))); } catch (Exception e) { e.printStackTrace(); } return doc; } }