Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import org.w3c.dom.Document;

import java.io.File;

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

import jdk.nashorn.internal.runtime.ParserException;

public class Main {
    private static Document parseXml(String xmlPath) {
        Document doc = null;
        try {
            File trainSchedule = new File(xmlPath);
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            doc = builder.parse(trainSchedule);
            doc.getDocumentElement().normalize();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        if (doc == null)
            throw new ParserException("cannot parse: \"" + xmlPath + "\"");

        return doc;
    }
}