Java tutorial
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.InputStream; import java.io.Reader; import java.net.URL; import javax.xml.parsers.DocumentBuilder; import org.w3c.dom.Document; import org.xml.sax.InputSource; public class Main { private static DocumentBuilder builder = null; private static final Object lock = new Object(); public static Document createDocument(File file) throws Exception { // handler.clear(); synchronized (lock) { return builder.parse(file); } } public static Document createDocument(Reader reader) throws Exception { // handler.clear(); synchronized (lock) { return builder.parse(new InputSource(reader)); } } public static Document createDocument(InputStream inputStream) throws Exception { // handler.clear(); synchronized (lock) { return builder.parse(inputStream); } } public static Document createDocument(String uri) throws Exception { // handler.clear(); URL url = new URL(uri); synchronized (lock) { return builder.parse(url.openStream()); } } public static Document createDocument(URL url) throws Exception { // handler.clear(); synchronized (lock) { return builder.parse(url.openStream()); } } }