Java Utililty Methods XML Child Get

List of utility methods to do XML Child Get

Description

The list of methods to do XML Child Get are organized into topic(s).

Method

ListgetChildElements(Element ele, String childEleName)
Retrieve all child elements of the given DOM element that match the given element getName.
NodeList nl = ele.getChildNodes();
List<Node> childEles = new ArrayList<Node>();
for (int i = 0; i < nl.getLength(); i++) {
    Node node = nl.item(i);
    if (node instanceof Element && nodeNameEquals(node, childEleName))
        childEles.add(node);
return childEles;
...
ListgetChildElements(Element elem, String name)
get Child Elements
NodeList nodes = elem.getElementsByTagName(name);
List<Element> elements = new ArrayList<Element>(nodes.getLength());
for (int i = 0; i < nodes.getLength(); i++) {
    Node node = nodes.item(i);
    if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(name)) {
        elements.add((Element) node);
return elements;
ListgetChildElements(Element element)
get single element by tag name.
return toElements(element.getChildNodes());
ListgetChildElements(Element element)
get Child Elements
final List<Element> list = new ArrayList<Element>();
final NodeList childNodes = element.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
    final Node node = childNodes.item(i);
    if (node instanceof Element) {
        list.add((Element) node);
return list;
ListgetChildElements(Element element)
get Child Elements
List<Element> list = new ArrayList<Element>();
NodeList nodeList = element.getChildNodes();
int size = nodeList.getLength();
for (int i = 0; i < size; i++) {
    Node childNode = nodeList.item(i);
    if (childNode instanceof Element) {
        list.add((Element) childNode);
return list;
ListgetChildElements(Element element)
get single element by tag name
List<Element> elems = new ArrayList<Element>();
NodeList list = element.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
    Node node = list.item(i);
    if (node instanceof Element) {
        Element e = (Element) node;
        elems.add(e);
return elems;
ListgetChildElements(Element element)
get Child Elements
List<Element> result = new ArrayList<Element>();
NodeList childNodes = element.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
    if (childNodes.item(i) instanceof Element) {
        result.add((Element) childNodes.item(i));
return result;
...
Element[]getChildElements(Element element)
Get the Element children of an element as an array.
NodeList childNodes = element.getChildNodes();
List<Element> kids = new ArrayList<Element>();
Node node = childNodes.item(0);
while (node != null) {
    if (node instanceof Element) {
        kids.add((Element) node);
    node = node.getNextSibling();
...
ListgetChildElements(Element element)
get Child Elements
NodeList nodeList = element.getChildNodes();
List<Element> elements = new ArrayList<>(nodeList.getLength());
for (int i = 0; i < nodeList.getLength(); i++) {
    Node node = nodeList.item(i);
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element childElement = (Element) node;
        boolean ignoreNode = false;
        NodeList childNodeList = childElement.getChildNodes();
...
ListgetChildElements(Element element)
get Child Elements
List<Element> elements = new LinkedList<Element>();
NodeList children = element.getChildNodes();
if (children == null) {
    return elements;
for (int i = 0, j = children.getLength(); i < j; i++) {
    Node child = children.item(i);
    if (child.getNodeType() == Node.ELEMENT_NODE) {
...