append Text XML Element - Java XML

Java examples for XML:DOM Element Create

Description

append Text XML Element

Demo Code


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

public class Main {
    public static void appendTextElement(Document doc, Element parent,
            String name, String value) {
        Element el = newTextElement(doc, name, value);
        parent.appendChild(el);/* w  ww  .j a  v  a 2 s.  c  om*/
    }

    public static Element newTextElement(Document doc, String nodeName,
            String value) {
        Element result = doc.createElement(nodeName);
        Text t = doc.createTextNode(value);
        result.appendChild(t);

        return result;
    }
}

Related Tutorials