Here you can find the source of loadDocument(File documentFile)
Parameter | Description |
---|---|
documentFile | The file to load. |
Parameter | Description |
---|---|
ParserConfigurationException | an exception |
SAXException | an exception |
IOException | an exception |
public static Document loadDocument(File documentFile) throws ParserConfigurationException, SAXException, IOException
//package com.java2s; /*-------------------------------------------------------------------------- * Copyright (c) 2004, 2006 OpenMethods, LLC * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from ww w .jav a 2 s .c om*/ * Trip Gilman (OpenMethods), Lonnie G. Pryor (OpenMethods), * Vincent Pruitt (OpenMethods) * * T.D. Barnes (OpenMethods) - initial API and implementation -------------------------------------------------------------------------*/ import java.io.File; import java.io.IOException; 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 { /** * Loads the given file using the default XML DOM implementation. * * @param documentFile The file to load. * @return The DOM document contained in the file. * @throws ParserConfigurationException * @throws SAXException * @throws IOException */ public static Document loadDocument(File documentFile) throws ParserConfigurationException, SAXException, IOException { DocumentBuilder documentBuilder = getDocumentBuilder(); return documentBuilder.parse(documentFile); } /** * Convenience function to get a DOM document builder object. * * @return A new <code>DocumentBuilder</code> instance. * @throws ParserConfigurationException */ public static DocumentBuilder getDocumentBuilder() throws ParserConfigurationException { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); return documentBuilderFactory.newDocumentBuilder(); } }