Here you can find the source of setTextContent(Element node, String text)
public static void setTextContent(Element node, String text)
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { public static void setTextContent(Element node, String text) { // this method is useful when DOM Level 3 "setTextContent" is not implemented final NodeList children = node.getChildNodes(); for (int i = (children.getLength() - 1); i > -1; i--) { node.removeChild(children.item(i)); }// w ww . java2 s .co m node.appendChild(node.getOwnerDocument().createTextNode(text)); } }