Java tutorial
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Element; public class Main { public static Element createElement(Element parent, String tagName) { Document doc = parent.getOwnerDocument(); Element child = doc.createElement(tagName); parent.appendChild(child); return child; } public static void createElement(Element parent, String elementName, String text) { Document doc = parent.getOwnerDocument(); Element id = doc.createElement(elementName); id.setTextContent(text); parent.appendChild(id); } }