Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

public class Main {
    /**
     * Convert XML from file path to a XML DOM document
     *
     * @param strXMLFilePath
     *            XML file path
     * @return XML DOM document
     * @throws Exception
     *             in error case
     */
    public static Document xmlFileToDOMDocument(String strXMLFilePath) throws Exception {
        if (strXMLFilePath == null) {
            throw new RuntimeException("No XML path given (null)!");
        }

        Document doc = null;
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            File xmlFile = new File(strXMLFilePath);
            doc = db.parse(xmlFile);
            doc.getDocumentElement().normalize();
        } catch (Exception e) {
            //            Logger.XMLEval.logState("Parsing of XML input failed: " + e.getMessage(), LogLevel.Error);
            throw e;
        }

        return doc;
    }
}