Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.slf4j.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import java.nio.file.*;

public class Main {
    static Logger log;

    public static Document DocumentFactory(Path xmlfile) {
        //get document object of the xml file
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        Document document = null;
        try {
            DocumentBuilder builder = builderFactory.newDocumentBuilder();
            document = builder.parse(xmlfile.toFile());
        } catch (ParserConfigurationException e) {
            log.error("DOM parser configuration exception");
            e.printStackTrace();
        } catch (SAXException e) {
            log.error("DOM parse error");
            e.printStackTrace();
        } catch (IOException e) {
            log.error("IO exception");
            e.printStackTrace();
        }
        return document;
    }
}