Java tutorial
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Document; import org.w3c.dom.NodeList; public class Main { /** * Set the value of the first tag found with the given name in the given document<br/>. If the tag with the * requested name doesn't have a child as textnode with the tagValue is created. * * @param doc * @param tagName * @param tagValue */ public static void setTagValue(Document doc, String tagName, String tagValue) { NodeList tagList = doc.getElementsByTagName(tagName); if (tagList.getLength() > 0) { if (tagList.item(0).getFirstChild() != null) { tagList.item(0).getFirstChild().setNodeValue(tagValue); } else { tagList.item(0).appendChild(doc.createTextNode(tagValue)); } } } }