Here you can find the source of removeWhitespace(Node parent)
public static void removeWhitespace(Node parent)
//package com.java2s; //License from project: LGPL import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static void removeWhitespace(Node parent) { parent.normalize();//from w w w .j a v a 2 s.com NodeList nodes = parent.getChildNodes(); if (nodes != null) { for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { removeWhitespace((Element) node); } else if (node.getNodeType() == Node.TEXT_NODE) { String text = node.getNodeValue().trim(); node.setNodeValue(text); } } } } }