Here you can find the source of getXMLFile(URL url)
Parameter | Description |
---|---|
url | - url |
Parameter | Description |
---|---|
ParserConfigurationException | - thrown if the document can not be parsed as an XML |
IOException | - thrown if the URL can not be opened |
SAXException | an exception |
public static Document getXMLFile(URL url) throws ParserConfigurationException, IOException, SAXException
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Document; import org.xml.sax.SAXException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import java.io.*; import java.net.URL; public class Main { public static Document getXMLFile(String url) throws ParserConfigurationException, IOException, SAXException { return getXMLFile(new URL(url)); }//w w w .ja va2s . c om /** * Gets an XML file from an url * * @param url - url * @return Document that is an XML file * @throws ParserConfigurationException - thrown if the document can not be parsed as an XML * @throws IOException - thrown if the URL can not be opened * @throws SAXException */ public static Document getXMLFile(URL url) throws ParserConfigurationException, IOException, SAXException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); return db.parse(url.openStream()); } }