Here you can find the source of removeChildNodes(Node node, short... ignoreNodeTypes)
Parameter | Description |
---|---|
node | a parameter |
public static void removeChildNodes(Node node, short... ignoreNodeTypes)
//package com.java2s; import java.util.HashSet; import java.util.LinkedHashSet; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**//from w ww . j a v a2 s . c om * @param node */ public static void removeChildNodes(Node node, short... ignoreNodeTypes) { HashSet<Node> childNodesSet = getValidChildNodes(node, false, ignoreNodeTypes); for (Node childNode : childNodesSet) { node.removeChild(childNode); } } /** * Returns only the valid child nodes of a node. Eliminates the nodes from * the list of child nodes of the input node if the child node type is same * with any of <code>ignoreNodeTypes</code> * * @param node * @param maintainOrder * @param ignoreNodeTypes * @return HashSet<Node> */ public static HashSet<Node> getValidChildNodes(Node node, boolean maintainOrder, short... ignoreNodeTypes) { NodeList childNodes = node.getChildNodes(); HashSet<Node> filteredChildNodes = new HashSet<Node>(); if (maintainOrder) { filteredChildNodes = new LinkedHashSet<Node>(); } for (int i = 0; i < childNodes.getLength(); i++) { Node thisNode = childNodes.item(i); boolean allowAdd = true; for (int j = 0; j < ignoreNodeTypes.length; j++) { if (ignoreNodeTypes[j] == thisNode.getNodeType()) { allowAdd = false; break; } } if (allowAdd) { filteredChildNodes.add(thisNode); } } return filteredChildNodes; } }