Java tutorial
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.Text; public class Main { public static Element createTextElement(Document document, String tag, String text) { if (document == null || tag == null || text == null) { return null; } Element element = document.createElement(tag); Text textNode = document.createTextNode(text); element.appendChild(textNode); return element; } public static void appendChild(Node node, Node child) { if (node != null && child != null) { node.appendChild(child); } } }