Java XML Node Remove removeAll(Node node, short nodeType, String name)

Here you can find the source of removeAll(Node node, short nodeType, String name)

Description

remove All

License

Apache License

Declaration

public static void removeAll(Node node, short nodeType, String name) 

Method Source Code

//package com.java2s;
/*/*from   w  w w . ja v  a2s  . c  om*/
 * Copyright 2013 Keith D Swenson
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Contributors Include: Shamim Quader, Sameer Pradhan, Kumar Raja, Jim Farris,
 * Sandia Yang, CY Chen, Rajiv Onat, Neal Wang, Dennis Tam, Shikha Srivastava,
 * Anamika Chaudhari, Ajay Kakkar, Rajeev Rastogi
 */

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

public class Main {
    public static void removeAll(Node node, short nodeType, String name) {
        if (node == null) {
            return; //ignore if passed a null
        }
        if (node.getNodeType() == nodeType && (name == null || node.getNodeName().equals(name))) {
            node.getParentNode().removeChild(node);
        } else {
            // Visit the children
            NodeList list = node.getChildNodes();
            for (int i = 0; i < list.getLength(); i++) {
                removeAll(list.item(i), nodeType, name);
            }
        }
    }
}

Related

  1. removeAll(final Node node, final short nodeType, final String name)
  2. removeAll(Node node)
  3. removeAll(Node node, short nodeType, String name)
  4. removeContents(Node parent)
  5. removeElement(Element parent, String tagName)
  6. removeElements(Node parent, String nature)
  7. removeElementXML(Node node, short nodeType, String name)