Java tutorial
//package com.java2s; //License from project: Apache License import org.w3c.dom.*; public class Main { public static Element appendChildElementString(Element parentNode, String tagName, String content) { Element elem = appendChildElement(parentNode, tagName); setTextContent(elem, content); return elem; } public static Element appendChildElement(Element parentNode, String nodeName) { Document doc = parentNode.getOwnerDocument(); Element childNode = doc.createElement(nodeName); parentNode.appendChild(childNode); return childNode; } public static void setTextContent(Element elem, String content) { Document doc = elem.getOwnerDocument(); if ((content != null) && !content.equals("")) { Text textNode = doc.createTextNode(content); elem.appendChild(textNode); } } }