Java tutorial
//package com.java2s; /******************************************************************************* * Copyright (c) 2004-2010 Sunil Kamath (IcemanK). All rights reserved. This * program is made available under the terms of the Common Public License v1.0 * which is available at http://www.eclipse.org/legal/cpl-v10.html * * Contributors: Sunil Kamath (IcemanK) - initial API and implementation *******************************************************************************/ import java.util.*; import org.w3c.dom.*; public class Main { public static Node[] findChildren(Node node) { return findChildren(node, null); } public static Node[] findChildren(Node node, String name) { List<Node> list = new ArrayList<Node>(); NodeList childNodes = node.getChildNodes(); int count = childNodes.getLength(); for (int i = 0; i < count; i++) { Node child = childNodes.item(i); if (child instanceof Element && (name == null || child.getNodeName().equals(name))) { list.add(child); } } return list.toArray(new Node[list.size()]); } }