Here you can find the source of readXmlFromUrl(String address)
public static Document readXmlFromUrl(String address)
//package com.java2s; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; 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 { public static Document readXmlFromUrl(String address) { Document document = null; HttpURLConnection urlConnection = null; try {/*from w w w . j av a 2s. c o m*/ URL url = new URL(address); urlConnection = (HttpURLConnection) url.openConnection(); InputStream inputStream = new BufferedInputStream( urlConnection.getInputStream()); // Create XML document from connection DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.parse(inputStream); } catch (MalformedURLException e) { throw new IllegalArgumentException("Malformed address " + address); } catch (IOException e) { throw new IllegalArgumentException("Unable to open adress"); } catch (ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { urlConnection.disconnect(); } return document; } }