Java tutorial
//package com.java2s; //License from project: LGPL import java.io.IOException; import java.io.InputStream; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.xml.sax.SAXException; public class Main { /** * Read input stream into XML Document element * * @param is * @return * @throws ParserConfigurationException * @throws SAXException * @throws IOException */ public static Document readXML(InputStream is) throws ParserConfigurationException, SAXException, IOException { javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder(); org.w3c.dom.Document doc = db.parse(is); return doc; } /** * Read a XML text file to XML Document object * * @param xmlFile * @return * @throws ParserConfigurationException * @throws SAXException * @throws IOException */ public static Document readXML(String xmlFile) throws ParserConfigurationException, SAXException, IOException { javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder(); org.w3c.dom.Document doc = db.parse(xmlFile); return doc; } }