Java XML Node Remove removeNodes(Element parent, NodeList elements)

Here you can find the source of removeNodes(Element parent, NodeList elements)

Description

remove Nodes

License

Open Source License

Declaration

public static void removeNodes(Element parent, NodeList elements) 

Method Source Code

//package com.java2s;
/**//  w  ww.  j av a 2s. co  m
 * This file belongs to the BPELUnit utility and Eclipse plugin set. See enclosed
 * license file for more information.
 */

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static void removeNodes(Element parent, NodeList elements) {
        // Copy elements in case of NodeList is a live implementation
        // that would shrink while deleting elments
        List<Node> nodesToRemove = new ArrayList<Node>();

        for (int i = 0; i < elements.getLength(); i++) {
            Node item = elements.item(i);

            if (item.getParentNode() == parent) {
                nodesToRemove.add(item);
            }
        }

        for (Node n : nodesToRemove) {
            parent.removeChild(n);
        }
    }
}

Related

  1. removeNode(final Node node)
  2. removeNode(Node node)
  3. removeNode(Node node)
  4. removeNode(Node node)
  5. removeNodeFromParent(Node node)
  6. removeNodesByName(Node node, String name)
  7. removePreviousWhiteSpace(Node node)
  8. removeQueryCallBody(Node queryElement)
  9. removeSelf(Node node)