Java Utililty Methods XML Child Get by Name

List of utility methods to do XML Child Get by Name

Description

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

Method

ElementgetChildByName(Element parent, String name)
get Child By Name
NodeList children = parent.getChildNodes();
if (children == null)
    return null;
for (int i = 0; i < children.getLength(); i++) {
    Node child = children.item(i);
    if (child.getNodeName().equalsIgnoreCase(name)) {
        return (Element) child;
return null;
ElementgetChildByName(Element parent, String name)
get Child By Name
return (Element) parent.getElementsByTagName(name).item(0);
ElementgetChildByName(final Element parent, final String name)
get Child By Name
if (parent == null || name == null)
    return null;
final NodeList list = parent.getChildNodes();
for (int k = 0, listCount = list.getLength(); k < listCount; k++) {
    final Node child = list.item(k);
    if (child.getNodeType() == Node.ELEMENT_NODE && nodeNameEqualToWithNoNamespace(child, name))
        return (Element) child;
return null;
ElementgetChildByName(final Element parent, final String name)
Gets the child by name.
if (parent == null || name == null)
    return null;
final NodeList list = parent.getChildNodes();
for (int k = 0, listCount = list.getLength(); k < listCount; k++) {
    final Node child = list.item(k);
    if (child.getNodeType() == Node.ELEMENT_NODE && nodeNameEqualToWithNoNamespace(child, name))
        return (Element) child;
return null;
NodegetChildByName(Node node, String name)
Returns the first child of a node with a specified name.
try {
    NodeList list = node.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
        if (list.item(i).getNodeName().equals(name)) {
            return list.item(i);
    return null;
...
NodegetChildByName(Node node, String name)
get Child By Name
NodeList nl = node.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
    if (nl.item(i).getNodeName().equals(name))
        return nl.item(i);
return null;
NodegetChildByName(Node node, String name)
get Child By Name
NodeList children = node.getChildNodes();
for (int j = 0; j < children.getLength(); j++) {
    Node child = children.item(j);
    if (child.getNodeName().equals(name)) {
        return child;
return null;
...
NodegetChildByName(Node node, String nodeName)
Find node by name.
org.w3c.dom.NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
    Node c = children.item(i);
    if (c.getNodeName().equals(nodeName))
        return c;
return null;
ElementgetChildByTagName(Element e, String name)
get Child By Tag Name
for (Node kid = e.getFirstChild(); kid != null; kid = kid.getNextSibling()) {
    if ((kid.getNodeType() == Node.ELEMENT_NODE) && (name.equals(kid.getNodeName()))) {
        return (Element) kid;
return null;
ElementgetChildByTagName(Element element, String childElementName)
get Child By Tag Name
return org.springframework.util.xml.DomUtils.getChildElementByTagName(element, childElementName);