Here you can find the source of findElementsByName(Node node, List
Parameter | Description |
---|---|
node | - current node |
name | - name element |
elements | - list of found elements |
static public void findElementsByName(Node node, List<Node> elements, String name)
//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); } } } }