Java XML Child Node Get getChildNodes(final Node node, final short nodetype)

Here you can find the source of getChildNodes(final Node node, final short nodetype)

Description

Gets the given node's children of the given type.

License

Open Source License

Parameter

Parameter Description
node parent.
nodetype searched child type.

Return

children.

Declaration

public static List<Node> getChildNodes(final Node node, final short nodetype) 

Method Source Code

//package com.java2s;
/**//  w w  w.  j  av  a 2  s .  co m
 * Copyright ? Microsoft Open Technologies, Inc.
 *
 * All Rights Reserved
 *
 * 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
 *
 * THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
 * ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A
 * PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
 *
 * See the Apache License, Version 2.0 for the specific language
 * governing permissions and limitations under the License.
 */

import java.util.ArrayList;

import java.util.List;

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

public class Main {
    /**
     * Gets the given node's children of the given type.
     *
     * @param node parent.
     * @param nodetype searched child type.
     * @return children.
     */
    public static List<Node> getChildNodes(final Node node, final short nodetype) {
        final List<Node> result = new ArrayList<Node>();

        final NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            final Node child = children.item(i);
            if (child.getNodeType() == nodetype) {
                result.add(child);
            }
        }

        return result;
    }
}

Related

  1. getChildNodeByType(Element element, short nodeType)
  2. getChildNodeGentle(Node node, String namespace, String localname)
  3. getChildNodeListByTagName(Element parent, String tagName)
  4. getChildNodes(Element ele)
  5. getChildNodes(final Node node)
  6. getChildNodes(final Node node, final String attributeName, final String value)
  7. getChildNodes(final Node node, short... types)
  8. getChildNodes(final Node parent, boolean recursiveSearch, final String... nodeNames)
  9. getChildNodes(Node node)