Add a Text element to XML Document - Java XML

Java examples for XML:DOM Document

Description

Add a Text element to XML Document

Demo Code


//package com.java2s;

import org.w3c.dom.*;

public class Main {
    /** Add a Text element to a Document */
    public static Text addChildTextElement(Document doc, Node parent,
            String tag, String value) {

        Element e = doc.createElement(tag);
        Text t = doc.createTextNode(value);
        e.appendChild(t);/*  w  ww.  j a  va  2 s.co  m*/
        parent.appendChild(e);
        return t;
    }
}

Related Tutorials