Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.File;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

public class Main {
    /**
     * Loads an xml file on disk into a document
     *
     * @param  xmlFileName - name of the file on disk, including path
     * @return Document    - loaded from the specified xml file on disk
     */
    public static Document loadXmlFromFile(String xmlFileName) {
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        docFactory.setNamespaceAware(true);

        try {
            return docFactory.newDocumentBuilder().parse(new File(xmlFileName));
        } catch (ParserConfigurationException e) {
            throw new RuntimeException("Error setting up UI xml page model parser -- " + e.getMessage());
        } catch (SAXException e) {
            throw new RuntimeException(
                    "Error parsing UI xml page model file [" + xmlFileName + "]  -- " + e.getMessage());
        } catch (IOException e) {
            throw new RuntimeException(
                    "Error opening or reading UI xml page model file [" + xmlFileName + "]  -- " + e.getMessage());
        }
    }
}