Java tutorial
//package com.java2s; /* * JFox - The most lightweight Java EE Application Server! * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn. * * JFox is licenced and re-distributable under GNU LGPL. */ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static List<Element> getElementsByTagNames(Element element, String[] tagNames) { List<Element> children = new ArrayList<Element>(); if (element != null && tagNames != null) { List tagList = Arrays.asList(tagNames); NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node child = nodes.item(i); if (child.getNodeType() == Node.ELEMENT_NODE && tagList.contains(((Element) child).getTagName())) { children.add((Element) child); } } } return children; } }