Java XML Node Name getNodes(Node node, String nodeName)

Here you can find the source of getNodes(Node node, String nodeName)

Description

Searches parent node for matching child nodes.

License

Open Source License

Parameter

Parameter Description
node The parent node
nodeName The child node's element name

Return

A list of matching child Nodes

Declaration

public static Iterator getNodes(Node node, String nodeName) 

Method Source Code

//package com.java2s;
/*/*from   w  w  w.  j ava 2s  .  c o m*/
 * XMLUtility.java  2/6/13 1:04 PM
 *
 * Copyright (C) 2012-2013 Nick Ma
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

import java.util.ArrayList;

import java.util.Iterator;

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

public class Main {
    /**
     * Searches parent node for matching child nodes.
     *
     * @param node     The parent node
     * @param nodeName The child node's element name
     * @return A list of matching child Nodes
     */
    public static Iterator getNodes(Node node, String nodeName) {
        ArrayList nodes = new ArrayList();
        NodeList nl = node.getChildNodes();
        int nll = nl.getLength();
        for (int i = 0; i < nll; i++) {
            Node n = nl.item(i);
            if (n.getNodeName().equals(nodeName)) {
                nodes.add(n);
            }
        }
        return nodes.iterator();
    }
}

Related

  1. getNodeNameIgnorePrefix(Node node)
  2. getNodeNames(Set nodes)
  3. getNodeNameWithNamespace(Node node)
  4. getNodes(Node iNode, String iNodeName)
  5. getNodes(Node module, String interfaceName, String nodeName)
  6. getSimpleName(final Node node)
  7. getSubNodes(Node node, String subNodeName)
  8. getSubNodeValue(Node node, String nodeName, String subNodeName)
  9. getTagName(Node labelNode)