Java tutorial
//package com.java2s; import java.io.IOException; import java.net.URL; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.xml.sax.SAXException; public class Main { /** Returns the document located at the specific URL. * @throw IllegalArgumentException if an error occurs. */ static public Document getDocument(URL url) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = null; try { db = dbf.newDocumentBuilder(); } catch (ParserConfigurationException ex) { throw new IllegalArgumentException(ex); } Document doc = null; try { doc = db.parse(url.toString()); } catch (SAXException ex) { throw new IllegalArgumentException(ex); } catch (IOException ex) { throw new IllegalArgumentException(ex); } return doc; } }