Java tutorial
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * This method is used for updating the value of a tag in a * <code>Document</code> object. * * @param doc * Document object * @param tagName * name of the tag * @param tagValue * the updated value of the tag */ public static void replaceTagValue(Document doc, String tagName, String tagValue) { NodeList nodeList = doc.getElementsByTagName(tagName); int j = nodeList.getLength(); Node node; for (int i = 0; i < j; i++) { Node newNode = doc.createTextNode(tagValue); node = nodeList.item(i); if (node.getFirstChild() != null) { node.replaceChild(newNode, node.getFirstChild()); } else { node.appendChild(newNode); } } } }