Java tutorial
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.net.URL; import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; public class Main { public static Document getXmlDocFromURI(String xmlFile) throws Exception { if (xmlFile.startsWith("http")) return getXmlDocFromURI(new URL(xmlFile).openStream()); else return getXmlDocFromURI(new FileInputStream(new File(xmlFile))); } public static Document getXmlDocFromURI(InputStream is) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); dbf.setNamespaceAware(true); return dbf.newDocumentBuilder().parse(is); } }