A method to create an element to associate to xml document by providing node name & value - Java XML

Java examples for XML:DOM Node Value

Description

A method to create an element to associate to xml document by providing node name & value

Demo Code


//package com.java2s;
import org.w3c.dom.Element;
import org.w3c.dom.Text;

import org.w3c.dom.Document;

public class Main {
    /**/* ww  w  .j  a  v  a  2  s  .c  om*/
     * A method to create an element to associate to xml document by providing node name & value
     * @param Document doc, xml document object where the element is going to associate
     * @param String tag, the element name to create
     * @param String value, the value for created element
     * @return Element , element object created
     */
    static public Element createElement(Document doc, String tag,
            String value) {

        Element e = doc.createElement(tag);
        Text t = doc.createTextNode(value);
        e.appendChild(t);
        return (e);
    }
}

Related Tutorials