Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * Copyright 2015 Yahoo Inc.<br>
 * Licensed under the terms of the MIT license. Please see LICENSE file at the root of this project for terms.
 * <p/>
 *
 * @author yuvalp@yahoo-inc.com
 * 
 */

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;

public class Main {
    /**
     * Creates a new element, with the given text inside that element.
     * 
     * @param document the document into which the element is added.
     * @param parentElement The parent element of the element-to-be-added.
     * @param newElementName name of new element (tag-name).
     * @param textString the text to be written inside the newly created element.
     * @return The new element.
     */
    public static Element addElementWithText(Document document, Element parentElement, String newElementName,
            String textString) {
        Element newElement = document.createElement(newElementName);
        Text text = document.createTextNode(textString);
        newElement.appendChild(text);
        parentElement.appendChild(newElement);
        return newElement;
    }
}