Java tutorial
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { /** * Create a new element in the parent node with the given local name. * @param parent The node to which the new element will be appended. * @param name The local name of the new element to be created * @return The newly created element. */ public static Element makeElement(Node parent, String name) { Document d = getDoc(parent); Element result = d.createElement(name); parent.appendChild(result); return result; } private static Document getDoc(Node n) { if (n instanceof Document) return (Document) n; else return n.getOwnerDocument(); } }