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 { /**/* www . ja va2s . c o m*/ * This method is useful when DOM Level 3 "setTextContent" is not implemented */ public static void setTextContent(Element node, String text) { final NodeList children = node.getChildNodes(); for (int i = (children.getLength() - 1); i > -1; i--) { node.removeChild(children.item(i)); } node.appendChild(node.getOwnerDocument().createTextNode(text)); } }