Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.IOException;
import java.io.InputStream;

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

import org.w3c.dom.Document;

public class Main {
    /**
     * parse XML document
     * @param in
     * @return
     * @throws IOException
     */
    public static Document parseXML(InputStream in) throws IOException {
        Document document = null;
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        //factory.setValidating(true);
        //factory.setNamespaceAware(true);

        try {
            DocumentBuilder builder = factory.newDocumentBuilder();
            //builder.setErrorHandler(new XmlErrorHandler());
            //builder.setEntityResolver(new XmlEntityResolver());
            document = builder.parse(in);

            // close input stream
            in.close();
        } catch (Exception ex) {
            throw new IOException(ex.getMessage());
        }
        return document;
    }
}