Java tutorial
//package com.java2s; /** * The contents of this file are subject to the OpenMRS Public License * Version 1.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://license.openmrs.org * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * Copyright (C) OpenMRS, LLC. All Rights Reserved. */ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import java.util.ArrayList; import java.util.List; public class Main { /** * Finds all children of a node with the given name * @param parent the parent node * @param name the name * @return the child nodes */ public static List<Node> findAllChildren(Node parent, String name) { List<Node> found = new ArrayList<Node>(); NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { Node node = children.item(i); if (name.equals(node.getNodeName())) { found.add(node); } } return found; } }