Here you can find the source of getFirstLevelChildElementsByTagName(Element parent, String elementName)
public static final List<Element> getFirstLevelChildElementsByTagName(Element parent, String elementName)
//package com.java2s; import java.util.ArrayList; import java.util.List; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static final List<Element> getFirstLevelChildElementsByTagName(Element parent, String elementName) { NodeList nodeList = parent.getChildNodes(); ArrayList<Element> childList = new ArrayList<Element>(nodeList.getLength()); Node childNode = parent.getFirstChild(); while (childNode != null) { if (childNode.getNodeType() == Node.ELEMENT_NODE) { String localName = ((Element) childNode).getLocalName(); if (localName.equals(elementName)) { childList.add((Element) childNode); }/* ww w.j a va2 s . com*/ } childNode = childNode.getNextSibling(); } return childList; } }