Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.io.*;
import java.net.URL;

public class Main {
    /**
     * StAX parse XML resource into XMLStreamReader
     * @return XMLStreamReader
     * @throws IOException
     * @throws XMLStreamException
     */
    public static XMLStreamReader parse(URL url) throws IOException, XMLStreamException {
        InputStream input = url.openStream();
        XMLInputFactory xif = XMLInputFactory.newInstance();
        XMLStreamReader xmlStreamReader = xif.createXMLStreamReader(input);

        return xmlStreamReader;
    }

    public static XMLStreamReader parse(File xmlFile) throws IOException, XMLStreamException {
        FileReader input = new FileReader(xmlFile);
        XMLInputFactory xif = XMLInputFactory.newInstance();
        XMLStreamReader xmlStreamReader = xif.createXMLStreamReader(input);

        return xmlStreamReader;
    }

    public static XMLStreamReader parse(String fileName) throws IOException, XMLStreamException {
        FileInputStream input = new FileInputStream(fileName);
        XMLInputFactory xif = XMLInputFactory.newInstance();
        XMLStreamReader xmlStreamReader = xif.createXMLStreamReader(input);

        return xmlStreamReader;
    }
}