Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import org.w3c.dom.Document;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import java.io.*;

public class Main {
    public static Document buildDocumentFromSource(InputSource is, boolean namespaceaware)
            throws ParserConfigurationException, SAXException, IOException {
        DocumentBuilder builder = getSyncDocumentBuilder(namespaceaware);
        //Parse the document
        Document doc = builder.parse(is);
        builder.reset();
        return doc;
    }

    public static DocumentBuilder getSyncDocumentBuilder(boolean namespaceAware)
            throws ParserConfigurationException {
        return getSyncDocumentBuilder(namespaceAware, false, false);
    }

    public static synchronized DocumentBuilder getSyncDocumentBuilder(boolean namespaceAware, boolean coalescing,
            boolean ignoringElementContentWhitespace) throws ParserConfigurationException {
        DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
        domFactory.setNamespaceAware(namespaceAware);
        domFactory.setCoalescing(coalescing);
        domFactory.setIgnoringElementContentWhitespace(ignoringElementContentWhitespace);
        return domFactory.newDocumentBuilder();
    }
}