Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import org.w3c.dom.*;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

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

import java.io.*;

public class Main {
    private final static DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

    /**
     * get the xml root document of the xml descriptor
     *
     * @param file the xml descriptor url
     * @return XML document
     * @throws IOException                  if failed to create XML document
     * @throws ParserConfigurationException e
     * @throws SAXException                 e
     */
    public static Document loadDocument(File file) throws IOException, ParserConfigurationException, SAXException {
        return dbf.newDocumentBuilder().parse(file);
    }

    /**
     * parse document from xml String
     *
     * @param xml xml string
     * @throws IOException                  if failed to create XML document
     * @throws ParserConfigurationException e
     * @throws SAXException                 e
     */
    public static Document loadDocument(String xml) throws IOException, ParserConfigurationException, SAXException {
        return dbf.newDocumentBuilder().parse(new InputSource(new StringReader(xml)));
    }
}