Java tutorial
//package com.java2s; /* Copyright (c) 2011 by crossmobile.org * * CrossMobile is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 2. * * CrossMobile is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with CrossMobile; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ import java.util.ArrayList; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static Node getNodeWithName(Node parent, String name) { ArrayList<Node> nodes = getNodesWithName(parent, name, false); if (nodes.size() < 1) return null; return nodes.get(0); } public static ArrayList<Node> getNodesWithName(Node parent, String name, boolean all_of_them) { ArrayList<Node> valid = new ArrayList<Node>(); NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); i++) if (children.item(i).getNodeName().equalsIgnoreCase(name)) { valid.add(children.item(i)); if (!all_of_them) break; } return valid; } }