Java XML Node Find findElementsByName(Node node, List elements, String name)

Here you can find the source of findElementsByName(Node node, List elements, String name)

Description

find elements by name.

License

Open Source License

Parameter

Parameter Description
node - current node
name - name element
elements - list of found elements

Declaration

static public void findElementsByName(Node node, List<Node> elements, String name) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
 * Distributed under license by Red Hat, Inc. All rights reserved.
 * This program is made available under the terms of the
 * Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from  ww w .ja  va 2s .  co  m*/
 *     Exadel, Inc. and Red Hat, Inc. - initial API and implementation
 ******************************************************************************/

import java.util.List;

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

public class Main {
    /**
     * find elements by name.
     * 
     * @param node - current node
     * @param name - name element
     * @param elements - list of found elements
     */
    static public void findElementsByName(Node node, List<Node> elements, String name) {
        // get children
        NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            // if current child is required then add his to list
            if (name.equalsIgnoreCase((child.getNodeName()))) {
                elements.add(child);
            } else {
                findElementsByName(child, elements, name);
            }
        }
    }
}

Related

  1. findElementById(Node node, String id)
  2. findElementByName(Node node, final String name)
  3. findElementByTag(Set nodes, String tag)
  4. findElementNodeByName(Node node, String name)
  5. findElements(Node fromnode, String name)
  6. findNode(Document source, Element n)
  7. findNode(Node aNode, String aName)
  8. findNode(Node node, String nodeName)
  9. findNode(Node rootNode, String nodeName)