Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

import org.eclipse.core.resources.IFile;

import org.eclipse.core.runtime.IProgressMonitor;
import org.w3c.dom.Document;

public class Main {
    public static Document open(IFile file, IProgressMonitor monitor) throws ParserConfigurationException {
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        if (!file.exists()) {
            return dBuilder.newDocument();
        }
        try {
            return dBuilder.parse(file.getContents());
        } catch (Exception e) {
            return dBuilder.newDocument();
        }
    }
}