/** * Creates a new XML DocumentBuilder * * @return a DocumentBuilder * @throws RuntimeException if we fail to create one */ public static DocumentBuilder getDocumentBuilder() { return getDocumentBuilder("com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", null); }
/** * Returns the parsed Document from an XML file * * @throws IllegalArgumentException if the file cannot be opened or parsed */ public static Document getDocument(File xmlFile) { try { return getDocumentBuilder().parse(xmlFile); } catch (IOException e) { throw new IllegalArgumentException("Could not read '" + xmlFile + "'", e); } catch (SAXParseException e) { throw new IllegalArgumentException("Could not parse '" + xmlFile + "', error at line " + e.getLineNumber() + ", column " + e.getColumnNumber(), e); } catch (SAXException e) { throw new IllegalArgumentException("Could not parse '" + xmlFile + "'", e); } }
/** * Returns the parsed Document from an XML file * * @throws IllegalArgumentException if the file cannot be opened or parsed */ public static Document getDocument(Reader reader) { try { return getDocumentBuilder().parse(new InputSource(reader)); } catch (IOException e) { throw new IllegalArgumentException("Could not read '" + reader + "'", e); } catch (SAXParseException e) { throw new IllegalArgumentException("Could not parse '" + reader + "', error at line " + e.getLineNumber() + ", column " + e.getColumnNumber(), e); } catch (SAXException e) { throw new IllegalArgumentException("Could not parse '" + reader + "'", e); } }