Java XML Child Remove All removeAllChildrenOfNode(Node node)

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

Description

remove All Children Of Node

License

EUPL

Declaration

public static void removeAllChildrenOfNode(Node node) 

Method Source Code

//package com.java2s;
/*// w ww. j  a v a  2  s.  c  om
 * Copyright 2015 Institute of Computer Science,
 * Foundation for Research and Technology - Hellas
 * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
 * You may not use this work except in compliance with the Licence.
 * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Licence for the specific language governing permissions and limitations under the Licence.
 *
 * Contact:  POBox 1385, Heraklio Crete, GR-700 13 GREECE
 * Tel:+30-2810-391632 Fax: +30-2810-391638 E-mail: isl@ics.forth.gr http://www.ics.forth.gr/isl
 *
 * Authors : Anyfantis Nikolaos (nanifant 'at' ics 'dot' forth 'dot' gr)
 *
 * This file is part of the Mapping Analyze (Maze) app.
 */

import org.w3c.dom.*;

public class Main {
    public static void removeAllChildrenOfNode(Node node) {
        for (int i = 0; i < node.getChildNodes().getLength(); i++) {
            Node n = node.getChildNodes().item(i);

            if (n.hasChildNodes()) //edit to remove children of children
            {
                removeAllChildrenOfNode(n);
                node.removeChild(n);
            } else
                node.removeChild(n);
        }
    }
}

Related

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