Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.File;

import javax.xml.parsers.DocumentBuilder;

import org.w3c.dom.Document;

public class Main {
    /**
     * load a xml file from OS file system and interpret it into a Document no
     * charset limited
     * 
     * @param xmlfile
     * @return Document
     * @throws Exception
     */
    public static Document load(String xmlfile) throws Exception {
        javax.xml.parsers.DocumentBuilderFactory factory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
        factory.setIgnoringComments(false);
        factory.setIgnoringElementContentWhitespace(false);
        factory.setValidating(false);
        factory.setCoalescing(true);
        DocumentBuilder builder = factory.newDocumentBuilder();

        return builder.parse(xmlfile);
    }

    /**
     * load a xml file from OS file system and interpret it into a Document no
     * charset limited
     * 
     * @param xmlfile
     *            String
     * @return Document
     * @throws Exception
     */
    public static Document load(File xmlfile) throws Exception {
        javax.xml.parsers.DocumentBuilderFactory factory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
        factory.setIgnoringComments(false);
        factory.setIgnoringElementContentWhitespace(false);
        factory.setValidating(false);
        factory.setCoalescing(true);
        DocumentBuilder builder = factory.newDocumentBuilder();

        return builder.parse(xmlfile);
    }
}