Java tutorial
//package com.java2s; import java.io.InputStream; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; public class Main { private static DocumentBuilderFactory documentBuilderFactory = null; public static Document parse(InputStream is) { try { return getDocumentBuilderFactory().newDocumentBuilder().parse(is); } catch (Exception e) { throw new IllegalStateException("Could not parse steam into Document", e); } } private static DocumentBuilderFactory getDocumentBuilderFactory() { if (documentBuilderFactory == null) { documentBuilderFactory = DocumentBuilderFactory.newInstance(); } return documentBuilderFactory; } }