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 org.w3c.dom.Document;
import org.w3c.dom.Element;

public class Main {
    /**
     * Returns a document with a HTML node containing a HEAD and BODY node.
     */
    public static Document createHtmlDocument() {
        Document document = createDocument();

        Element root = document.createElement("html");

        document.appendChild(root);

        Element head = document.createElement("head");
        root.appendChild(head);

        Element body = document.createElement("body");
        root.appendChild(body);

        return document;
    }

    /**
     * Returns a new, empty DOM document.
     * 
     * @return Returns a new DOM document.
     */
    public static Document createDocument() {
        Document result = null;

        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder parser = factory.newDocumentBuilder();

            result = parser.newDocument();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

        return result;
    }
}