Java tutorial
//package com.java2s; // modify it under the terms of the GNU General Public License import java.io.ByteArrayInputStream; import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import org.w3c.dom.Document; import org.xml.sax.SAXException; public class Main { private static DocumentBuilder builder = null; public static Document parse(java.io.InputStream in) throws SAXException, IOException { Document result = null; synchronized (builder) { result = builder.parse(in); } return result; } public static Document parse(String document) throws SAXException, IOException { return parse(new ByteArrayInputStream(document.getBytes())); } }