append XML Element Child With Text - Java XML

Java examples for XML:XML Element Child

Description

append XML Element Child With Text

Demo Code


//package com.java2s;
import org.w3c.dom.*;

public class Main {
    public static Element appendElementChildWithText(Document doc,
            Element parent, String name, String text) {
        Element el = appendElementChild(doc, parent, name);
        el.setTextContent(text);//from  w  w w.  j a  va  2  s.  com
        return el;
    }

    public static Element appendElementChild(Document doc, Element parent,
            String name) {
        Element el = doc.createElement(name);
        parent.appendChild(el);
        return el;
    }
}

Related Tutorials