Java tutorial
//package com.java2s; import java.net.URI; import java.net.URL; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.xml.sax.InputSource; public class Main { private static final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); public static Document load(String uri) { return load(new InputSource(uri)); } public static Document load(URI uri) { return load(new InputSource(uri.toString())); } public static Document load(URL url) { return load(new InputSource(url.toString())); } public static Document load(InputSource is) { try { DocumentBuilder db = dbf.newDocumentBuilder(); return db.parse(is); } catch (Exception e) { // Quick and dirty. Turn it into an unchecked exception. throw new RuntimeException(e); } } }