Java tutorial
//package com.java2s; import java.io.IOException; import java.io.InputStream; import javax.xml.parsers.DocumentBuilder; import org.w3c.dom.Document; import org.xml.sax.SAXException; public class Main { private static DocumentBuilder docBuilder; public static Document createDocument(InputStream is) throws SAXException, IOException { try { return docBuilder.parse(is); } finally { is.close(); } } public static Document createDocument() { return docBuilder.newDocument(); } }