Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;

public class Main {
    /**
     * Creates an XML {@link Document} with the provided root element tag.
     * We're using DOM for now - memory-intensive, but OK for these uses
     * @param ns The namespace URI of the document element to create, or null for none.
     * @param rootElement The name of the XML root element tag.
     * @return An XML {@link Document}.
     */
    public static Document createXmlDoc(String ns, String rootElement) {
        // Create XML DOM document (Memory consuming).
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = null;
        try {
            builder = factory.newDocumentBuilder();
        } catch (ParserConfigurationException e) {
        }
        DOMImplementation impl = builder.getDOMImplementation();
        // Document.
        return impl.createDocument(ns, rootElement, null);
    }
}