Java tutorial
//package com.java2s; /* * FFNLauncher * Copyright (C) 2013 Abel Hoogeveen <http://www.sigmacoders.nl> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.UnknownHostException; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.xml.sax.SAXException; public class Main { public static Document downloadXML(URL url) throws IOException, SAXException { return getXML(url.openStream()); } /** * Reads XML from a stream * @param stream the stream to read the document from * @return The document * @return The document * @throws IOException, SAXException if an error occurs when reading from the stream */ public static Document getXML(InputStream stream) throws IOException, SAXException { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); try { return docFactory.newDocumentBuilder().parse(stream); } catch (ParserConfigurationException ignored) { System.out.println("getXML parser error v001"); } catch (UnknownHostException e) { System.out.println("getXML UnknowHost error v002"); } return null; } }