Java Utililty Methods XML Child Node Get

List of utility methods to do XML Child Node Get

Description

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

Method

ListgetChildElements(Node node)
Returns a list of all child Elements,
return getChildElements(node, null);
ListgetChildElements(Node node)
get Child Elements
NodeList children = node.getChildNodes();
int childCount = children.getLength();
List<Node> nodes = new ArrayList<Node>(childCount);
for (int i = 0; i < childCount; i++) {
    Node child = children.item(i);
    if (child.getNodeType() == Node.ELEMENT_NODE) {
        nodes.add(child);
return nodes;
StreamgetChildElements(Node node)
get Child Elements
if (node == null) {
    return Stream.empty();
return toStream(node.getChildNodes()).filter(x -> x.getNodeType() == Node.ELEMENT_NODE)
        .map(x -> (Element) x);
CollectiongetChildElements(Node node)
get Child Elements
List<Element> elements = new ArrayList<Element>();
NodeList nodes = node.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
    Node childNode = nodes.item(i);
    if (childNode instanceof Element) {
        elements.add((Element) childNode);
return elements;
ListgetChildElements(Node parent)
returns List of all direct child elements
ArrayList retVec = new ArrayList();
NodeList children = parent.getChildNodes();
for (int i = 0; i < children.getLength(); ++i) {
    if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
        retVec.add(children.item(i));
return retVec;
...
ListgetChildElements(Node parent)
get Child Elements
List<Element> elements = new ArrayList<Element>();
for (Node n = parent.getFirstChild(); n != null; n = n.getNextSibling()) {
    if (n.getNodeType() == Node.ELEMENT_NODE) {
        elements.add((Element) n);
return elements;
ListgetChildElements(Node start)
returns a java.util.List of Elements which are children of the start Element.
List l = new ArrayList();
NodeList nl = start.getChildNodes();
int len = nl.getLength();
Node n = null;
for (int i = 0; i < len; i++) {
    n = nl.item(i);
    if (n.getNodeType() == Node.ELEMENT_NODE) {
        l.add(n);
...
ListgetChildElements(NodeList list)
get Child Elements
List<Element> result = new ArrayList<Element>();
for (int i = 0; i < list.getLength(); i++) {
    Node node = list.item(i);
    if (node instanceof Element) {
        Element el = (Element) node;
        result.add(el);
return result;
ElementgetChildNode(Element item, String name)
get Child Node
NodeList children = item.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
    Node thisItem = (Node) children.item(i);
    if (thisItem != null && thisItem.getNodeName().equals(name) && thisItem.getParentNode() == item) {
        return (Element) thisItem;
return null;
...
NodegetChildNode(Node n, String name)
get Child Node
if (n == null) {
    throw new IllegalArgumentException("null node");
if (name == null) {
    throw new IllegalArgumentException("null name");
NodeList l = n.getChildNodes();
for (int i = 0; i < l.getLength(); i++) {
...