Java XML Document Create getDocument(File file)

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

Description

get Document

License

Apache License

Declaration

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

Method Source Code


//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.Document;

import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;

public class Main {
    static public Document getDocument(File file) throws IOException, ParserConfigurationException, SAXException {
        InputStream stream = new FileInputStream(file);
        return getDocument(stream);
    }/*from  w w w .  ja va  2  s .c  o m*/

    static public Document getDocument(Path filePath)
            throws IOException, ParserConfigurationException, SAXException {
        return getDocument(filePath.toFile());
    }

    static public Document getDocument(InputStream stream)
            throws IOException, SAXException, ParserConfigurationException {
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();

        Document doc = dBuilder.parse(stream);
        doc.getDocumentElement().normalize();

        return doc;
    }
}

Related

  1. getDocument(File f)
  2. getDocument(File file)
  3. getDocument(File file)
  4. getDocument(File file)
  5. getDocument(File file)
  6. getDocument(final File file)
  7. getDocument(InputStream in)
  8. getDocument(InputStream input)
  9. getDocument(InputStream inputStream)