Java tutorial
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Element; public class Main { /** * Add a child element, whose text contents are the given int value. * * @param doc Document object, used to build new elements. * @param elem Element to append new child to. * @param childName Name of the new child element. * @param childText Text contents of the new child element. */ public static void addChildInt(Document doc, Element elem, String childName, int childValue) { addChildText(doc, elem, childName, Integer.toString(childValue)); } /** * Add a child element with the given text contents to the specified element. * * @param doc Document object, used to build new elements. * @param elem Element to append new child to. * @param childName Name of the new child element. * @param childText Text contents of the new child element. */ public static void addChildText(Document doc, Element elem, String childName, String childText) { Element newChild = doc.createElement(childName); newChild.setTextContent(childText); elem.appendChild(newChild); } }