Here you can find the source of createDocument(File file)
Parameter | Description |
---|---|
file | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
public static Document createDocument(File file) throws Exception
//package com.java2s; /*//from w w w. j a v a 2s. c o m * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.File; import java.io.InputStream; import java.io.Reader; import java.net.URL; import javax.xml.parsers.DocumentBuilder; import org.w3c.dom.Document; import org.xml.sax.InputSource; public class Main { private static DocumentBuilder builder = null; private static final Object lock = new Object(); /** * create org.w3c.dom.Document from file * @param file * @return * @throws Exception */ public static Document createDocument(File file) throws Exception { // handler.clear(); synchronized (lock) { return builder.parse(file); } } /** * create org.w3c.dom.Document from reader * @param reader * @return * @throws Exception */ public static Document createDocument(Reader reader) throws Exception { // handler.clear(); synchronized (lock) { return builder.parse(new InputSource(reader)); } } /** * create org.w3c.dom.Document from input stream * @param inputStream * @return * @throws Exception */ public static Document createDocument(InputStream inputStream) throws Exception { // handler.clear(); synchronized (lock) { return builder.parse(inputStream); } } /** * create org.w3c.dom.Document from uri * @param uri * @return * @throws Exception */ public static Document createDocument(String uri) throws Exception { // handler.clear(); URL url = new URL(uri); synchronized (lock) { return builder.parse(url.openStream()); } } /** * create org.w3c.dom.Document from URL * @param url * @return * @throws Exception */ public static Document createDocument(URL url) throws Exception { // handler.clear(); synchronized (lock) { return builder.parse(url.openStream()); } } }