Java tutorial
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Element; public class Main { public static void appendLeaf(Document doc, Element root, String name, String value) { root.appendChild(createLeaf(doc, name, value)); } public static Element createLeaf(Document doc, String name, String value) { Element leaf = doc.createElement(name); if (value != null) leaf.appendChild(doc.createTextNode(value)); return leaf; } }