Java tutorial
//package com.java2s; //License from project: Apache License import org.w3c.dom.*; public class Main { public static Element appendChildElementInt(Element parentNode, String tagName, int content) { Element elem = appendChildElement(parentNode, tagName); setIntContent(elem, content); return elem; } public static Element appendChildElement(Element parentNode, String nodeName) { Document doc = parentNode.getOwnerDocument(); Element childNode = doc.createElement(nodeName); parentNode.appendChild(childNode); return childNode; } public static void setIntContent(Element elem, int value) { setTextContent(elem, Integer.toString(value)); } public static void setTextContent(Element elem, String content) { Document doc = elem.getOwnerDocument(); if ((content != null) && !content.equals("")) { Text textNode = doc.createTextNode(content); elem.appendChild(textNode); } } }