Here you can find the source of replaceText(Node node, String text)
public static void replaceText(Node node, String text)
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Node; import org.w3c.dom.Text; public class Main { public static void replaceText(Node node, String text) { for (;;) { Node n = node.getFirstChild(); if (n == null) break; node.removeChild(n);//from ww w .j a v a 2 s. co m } Text t = node.getOwnerDocument().createTextNode(text); node.appendChild(t); } }