Here you can find the source of getDirectChildElementsOnly(QName qName, Element element)
public static List<Element> getDirectChildElementsOnly(QName qName, Element element)
//package com.java2s; //License from project: Open Source License import org.w3c.dom.*; import javax.xml.namespace.QName; import java.util.ArrayList; import java.util.List; public class Main { public static List<Element> getDirectChildElementsOnly(QName qName, Element element) { List<Element> elements = new ArrayList<>(); NodeList list = element.getChildNodes(); if (list == null || list.getLength() <= 0) { return elements; }/*w w w . ja va 2 s . com*/ for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (Node.ELEMENT_NODE == node.getNodeType()) { Element elem = (Element) node; if (qName == null) { elements.add(elem); } else if (qName.getNamespaceURI().equals(elem.getNamespaceURI())) { if (qName.getLocalPart().equals("*") || qName.getLocalPart().equals(elem.getLocalName())) { elements.add(elem); } } } } return elements; } }