Java tutorial
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Text; public class Main { public static void addNode(Document file, String text, String nodeName) { file.getDocumentElement().appendChild(file.createTextNode(" ")); addOneElement(file, text, nodeName); } private static void addOneElement(Document file, String text, String elementName) { Element newNode = file.createElement(elementName); Text textMsg = file.createTextNode(text); newNode.appendChild(textMsg); file.getDocumentElement().appendChild(newNode); file.getDocumentElement().appendChild(file.createTextNode("\n ")); } }