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 java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;

import javax.xml.parsers.DocumentBuilder;
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 {
    /**
     * Metodo para carregar o arquivo XML assinado e garantir que o XML esta bem formatado.
     * 
     * @param xmlFile arquivo XML assinado.
     * 
     * @return org.w3c.dom.Document 
     * @throws ParserConfigurationException 
     * @throws IOException 
     * @throws SAXException 
     */

    public static Document carregarArquivoXML(InputStream xmlFile)
            throws ParserConfigurationException, SAXException, IOException {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        Document doc = null;
        DocumentBuilder db;
        db = dbf.newDocumentBuilder();
        doc = db.parse(xmlFile);
        return doc;
    }

    /**
     * Metodo para carregar uma string contendo um arquivo xml assinado.
     * 
     * @param xmlString -> XML assinado.
     * 
     * @return org.w3c.dom.Document 
     * @throws ParserConfigurationException 
     * @throws IOException 
     * @throws SAXException 
     */

    public static Document carregarArquivoXML(String xmlString)
            throws ParserConfigurationException, SAXException, IOException {

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        Document doc = null;
        DocumentBuilder db;
        db = dbf.newDocumentBuilder();
        doc = db.parse(new InputSource(new StringReader(xmlString)));
        return doc;
    }

    /**
     * Metodo para carregar o arquivo XML assinado e garantir que o XML esta bem formatado.
     * 
     * @param xmlSource arquivo XML assinado.
     * 
     * @return org.w3c.dom.Document 
     * @throws ParserConfigurationException 
     * @throws IOException 
     * @throws SAXException 
     */

    public static Document carregarArquivoXML(InputSource xmlSource)
            throws ParserConfigurationException, SAXException, IOException {

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        Document doc = null;
        DocumentBuilder db;
        db = dbf.newDocumentBuilder();
        doc = db.parse(xmlSource);
        return doc;
    }
}