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

public class Main {
    /**
     * Add a child element, whose text contents are the given boolean value.
     * 
     * @param doc Document object, used to build new elements.
     * @param elem Element to append new child to.
     * @param childName Name of the new child element.
     * @param childValue Value of the new child element.
     */
    public static void addChildBoolean(Document doc, Element elem, String childName, boolean childValue) {
        addChildText(doc, elem, childName, Boolean.toString(childValue));
    }

    /**
     * Add a child element with the given text contents to the specified element.
     * 
     * @param doc Document object, used to build new elements.
     * @param elem Element to append new child to.
     * @param childName Name of the new child element.
     * @param childText Text contents of the new child element.
     */
    public static void addChildText(Document doc, Element elem, String childName, String childText) {
        Element newChild = doc.createElement(childName);
        newChild.setTextContent(childText);
        elem.appendChild(newChild);
    }
}