Java tutorial
//package com.java2s; import java.io.ByteArrayInputStream; import java.io.InputStream; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; public class Main { public static Document LoadXml(String xml) throws Exception { // create... ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes()); try { return LoadXml(stream); } finally { if (stream != null) stream.close(); } } private static Document LoadXml(InputStream stream) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); // builder... DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(stream); // return... return doc; } }