Java XML Document from File loadDocument(File file)

Here you can find the source of loadDocument(File file)

Description

load Document

License

Open Source License

Declaration

public static Document loadDocument(File file) throws ParserConfigurationException, SAXException, IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import java.io.IOException;
import java.io.InputStream;

import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;

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 {
    public static Document loadDocument(File file) throws ParserConfigurationException, SAXException, IOException {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        Document doc;//w  ww.  j a  v a  2  s .c  o  m
        DocumentBuilder db;

        db = dbf.newDocumentBuilder();
        doc = db.parse(file);

        return doc;
    }

    public static Document loadDocument(String path)
            throws ParserConfigurationException, SAXException, IOException {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        Document doc;
        DocumentBuilder db;

        db = dbf.newDocumentBuilder();
        doc = db.parse(new File(path));

        return doc;
    }

    public static Document loadDocument(InputStream is)
            throws ParserConfigurationException, SAXException, IOException {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        Document doc;
        DocumentBuilder db;

        db = dbf.newDocumentBuilder();
        doc = db.parse(is);

        return doc;
    }

    public static Document loadDocument(ReadableByteChannel in)
            throws ParserConfigurationException, SAXException, IOException {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        Document doc;
        DocumentBuilder db;

        db = dbf.newDocumentBuilder();
        doc = db.parse(Channels.newInputStream(in));

        return doc;
    }
}

Related

  1. getXmlDocument(String fileName)
  2. isXMLFile(File file)
  3. load(String file)
  4. load(String sFileName)
  5. loadDocument(File documentFile)
  6. loadDocument(String filePath)
  7. loadRootElement(DocumentBuilder documentBuilder, File file)
  8. loadXML(String filename)
  9. loadXml(String fileName)