Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/* Copyright (c) 2016 by crossmobile.org
 *
 * CrossMobile is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 2.
 *
 * CrossMobile is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with CrossMobile; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import java.io.Reader;

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

import org.w3c.dom.Document;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class Main {
    public static Document loadXML(File infile) {
        try {
            return loadXML(new FileInputStream(infile));
        } catch (FileNotFoundException ex) {
            return null;
        }
    }

    public static Document loadXML(InputStream in) {
        try {
            if (in != null)
                return DocumentBuilderFactory.newInstance().newDocumentBuilder()
                        .parse(new InputSource(new InputStreamReader(in, "UTF-8")));
        } catch (SAXException | IOException | ParserConfigurationException ex) {
        }
        return null;
    }

    public static Document loadXML(Reader r) {
        try {
            if (r != null)
                return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(r));
        } catch (SAXException | IOException | ParserConfigurationException ex) {
        }
        return null;
    }
}