Java tutorial
//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: * 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); } } } }