Java XML Node Append addDescendants(Node node, List descendants)

Here you can find the source of addDescendants(Node node, List descendants)

Description

Adds descendant elements of a node to a list.

License

Open Source License

Parameter

Parameter Description
node Node.
descendants List of descendants.

Declaration


public static void addDescendants(Node node, List<Node> descendants) 

Method Source Code


//package com.java2s;
/*   Please see the license information at the end of this file. */

import java.util.*;

import org.w3c.dom.*;

public class Main {
    /**   Adds descendant elements of a node to a list.
     *//from w ww. j a v a2 s  . c o m
     *   @param   node         Node.
     *
     *   @param   descendants      List of descendants.
     */

    public static void addDescendants(Node node, List<Node> descendants) {
        NodeList children = node.getChildNodes();
        int numChildren = children.getLength();
        for (int i = 0; i < numChildren; i++) {
            Node child = children.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                descendants.add(child);
                addDescendants(child, descendants);
            }
        }
    }
}

Related

  1. addComment(Node node, String comment)
  2. addImageSource(Node test, List holder)
  3. addNodeValue(Node node, String name, boolean value)
  4. addValue(Node node, String value)
  5. appendChild(Node parent, Node child)