Java XML NodeList size(final NodeList nodeList)

Here you can find the source of size(final NodeList nodeList)

Description

Retrieves the number of Nodes in the NodeList

License

Open Source License

Parameter

Parameter Description
nodeList the NodeList

Return

the number of Nodes

Declaration

public final static int size(final NodeList nodeList) 

Method Source Code

//package com.java2s;
/**//w  w w  . ja  v  a 2s . c o  m
 * The contents of this file are subject to the Regenstrief Public License
 * Version 1.0 (the "License"); you may not use this file except in compliance with the License.
 * Please contact Regenstrief Institute if you would like to obtain a copy of the license.
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) Regenstrief Institute.  All Rights Reserved.
 */

import org.w3c.dom.*;

public class Main {
    /**
     * Retrieves the number of Nodes in the NodeList
     * 
     * @param nodeList the NodeList
     * @return the number of Nodes
     **/
    public final static int size(final NodeList nodeList) {
        return nodeList == null ? 0 : nodeList.getLength();
    }

    /**
     * Retrieves the number of Nodes in the NamedNodeMap
     * 
     * @param nodeMap the NamedNodeMap
     * @return the number of Nodes
     **/
    public final static int size(final NamedNodeMap nodeMap) {
        return nodeMap == null ? 0 : nodeMap.getLength();
    }

    /**
     * Retrieves the number of Nodes in the tree rooted at the given Node
     * 
     * @param node the root Node
     * @return the number of Nodes
     **/
    public final static int size(final Node node) {
        if (node == null) {
            return 0;
        }

        final NodeList children = node.getChildNodes();
        int size = 1;
        for (int i = 0, n = size(children); i < n; i++) {
            size += size(children.item(i));
        }

        return size;
    }
}

Related

  1. replace(Node src, NodeList nodes)
  2. replaceElement(Element oldElement, NodeList newNodes)
  3. replaceElement(Element oldElement, NodeList newNodes)
  4. searchDialogByName(NodeList nodeList, String id)
  5. selectElement(NodeList nodeList, String name)
  6. sort(NodeList classesNodeList)
  7. stream(NodeList list)
  8. stream(NodeList nodeList)
  9. stream(NodeList nodes)