Java tutorial
//package com.java2s; import java.util.ArrayList; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { private static void cleanWhiteList(Node node, ArrayList<String> whiteList) { if (whiteList.contains(node.getLocalName())) { node.setNodeValue(null); node.setTextContent(null); // System.err.println("haha"); } NodeList children = node.getChildNodes(); if (children.getLength() != 0) { for (int i = 0; i < children.getLength(); i++) cleanWhiteList(children.item(i), whiteList); } } }