Here you can find the source of getChildElementsIntern(final Node node, final QName nodeName, final boolean recurse)
private static List<Element> getChildElementsIntern(final Node node, final QName nodeName, final boolean recurse)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.Collections; import java.util.List; import javax.xml.namespace.QName; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { private static List<Element> getChildElementsIntern(final Node node, final QName nodeName, final boolean recurse) { final ArrayList<Element> list = new ArrayList<Element>(); if (node == null) { return list; }/*from w ww . j a v a 2s .c om*/ final NodeList nlist = node.getChildNodes(); for (int i = 0; i < nlist.getLength(); i++) { final Node child = nlist.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { if (nodeName == null) { list.add((Element) child); } else { QName qname; if (nodeName.getNamespaceURI().length() > 0) { qname = new QName(child.getNamespaceURI(), child.getLocalName()); } else { qname = new QName( child.getLocalName() == null ? child.getNodeName() : child.getLocalName()); } if (qname.equals(nodeName)) { list.add((Element) child); } } if (recurse) { list.addAll(getChildElementsIntern(child, nodeName, true)); } } } return Collections.unmodifiableList(list); } }