Java tutorial
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.w3c.dom.Text; public class Main { public static void setValueByElementName(Document document, String name, String value) { if (document == null) { return; } NodeList nodeList = document.getElementsByTagName(name); if (nodeList != null && nodeList.getLength() > 0) { for (int i = 0; i < nodeList.getLength(); i++) { Element element = (Element) nodeList.item(i); ((Text) element.getFirstChild()).setData(value); } } } }