Java tutorial
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { /** * This method is used to insert a new tag below the tag specified by * <code>appendTo</code> parameter. * * @param d * the <code>Document</code> object to which a new tag is to be * inserted. * @param appendTo * the tag below which a new tag needs to be inserted. * @param tagName * the name of new tag * @param tagValue * the value of new tag */ public static Element insertNewTagBelow(Document d, String appendTo, String tagName, String tagValue) { Node element = d.getElementsByTagName(appendTo).item(0); if (element == null) { element = d.createElement(appendTo); } Element newElement = d.createElement(tagName); element.appendChild(newElement); newElement.appendChild(d.createTextNode(tagValue)); return newElement; } }