Here you can find the source of setText(Element element, String text)
public static void setText(Element element, String text)
//package com.java2s; //License from project: Apache License import org.w3c.dom.*; public class Main { public static void setText(Element element, String text) { if (text == null || "".equals(text)) { // ignore null/empty string text return; }// w w w. j a v a 2 s .c o m Text txt = element.getOwnerDocument().createTextNode(text); element.appendChild(txt); } }