Java XML Child Remove All removeAllChildren(Node node)

Here you can find the source of removeAllChildren(Node node)

Description

Removes all children nodes from the specified node.

License

Apache License

Parameter

Parameter Description
node the parent node whose children are to be removed

Declaration

public static void removeAllChildren(Node node) 

Method Source Code

//package com.java2s;
/**//from   w  w w  .  j a va  2 s  .  c o m
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you 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.
 */

import org.w3c.dom.Node;

public class Main {
    /**
     * Removes all children nodes from the specified node.
     *
     * @param node the parent node whose children are to be removed
     */
    public static void removeAllChildren(Node node) {
        Node firstChild = node.getFirstChild();
        while (firstChild != null) {
            Node nodeToRemove = firstChild;
            firstChild = firstChild.getNextSibling();
            node.removeChild(nodeToRemove);
        }
    }
}

Related

  1. removeAllChildren(Node node)
  2. removeAllChildren(Node node)
  3. removeAllChildren(Node node)
  4. removeAllChildren(Node node)
  5. removeAllChildren(Node node)
  6. removeAllChildren(org.w3c.dom.Element element)
  7. removeAllChildrenNotElement(Element parentElem)
  8. removeAllChildrenOfNode(Node node)
  9. removeAllNamedChild(Element parent, String name)