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

public class Main {
    public static Document startXMLDocument(String _firstTag) {
        DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = null;
        Document doc = null;
        try {
            docBuilder = dbfac.newDocumentBuilder();
            doc = docBuilder.newDocument();

            Element xmlRoot = doc.createElement(_firstTag);
            doc.appendChild(xmlRoot);

        } catch (ParserConfigurationException e) {
            System.out.println("C:" + e.getClass() + "\nM:" + e.getMessage());
            return null;
        }
        return doc;
    }
}