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

NodegetChildNode(Node parentNode, String childElementName)
get Child Node
NodeList l = parentNode.getChildNodes();
for (int i = 0; i < l.getLength(); i++) {
    Node node = l.item(i);
    if (node.getNodeName().equals(childElementName))
        return node;
return null;
NodegetChildNode(Node root, String childName)
Instead of using XPathAPI.selectSingleNode(root, "name")); use getChildNode(root, "name"); This is much quicker!
NodeList nl = root.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
    if (nl.item(i).getNodeName().equals(childName)) {
        return nl.item(i);
System.err.println("Childnode " + childName + " not found!");
return null;
...
NodegetChildNode(Node rootNode, String childName)
Returns the first child node of the given root node that has the given name.
NodeList nodeList = rootNode.getChildNodes();
for (int nodeIndex = 0, nodeSize = nodeList.getLength(); nodeIndex < nodeSize; nodeIndex++) {
    Node childNode = nodeList.item(nodeIndex);
    if (childNode.getNodeName().equals(childName)) {
        return childNode;
return null;
...
NodegetChildNodeByLocalName(final Node parentNode, final String localNodeName)
Get the a specific child node from its parent node by matching the local name.
final NodeList children = parentNode.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
    final Node child = children.item(i);
    if (child.getLocalName() != null) {
        if (child.getLocalName().equals(localNodeName)) {
            return child;
return null;
NodegetChildNodeByName(final Node xnode, final String name, final boolean caseSensitive)
Helper Method.
NodeList list = xnode.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
    Node node = list.item(i);
    if (caseSensitive) {
        if (node.getNodeName().equals(name))
            return node;
    } else {
        if (node.getNodeName().equalsIgnoreCase(name))
...
NodegetChildNodeByName(Node element, CharSequence nodeName, boolean caseSensitive)
Helper Method.
if (element == null)
    return null;
if (nodeName == null)
    return null;
final String name = nodeName.toString().trim();
if (name.isEmpty())
    return null;
NodeList list = element.getChildNodes();
...
NodegetChildNodeByName(Node node, String childName)
get Child Node By Name
NodeList children = node.getChildNodes();
for (int j = 0; j < children.getLength(); j++) {
    Node child = children.item(j);
    if (child.getNodeName().equals(childName)) {
        return child;
return null;
...
NodegetChildNodeByName(Node node, String name)
get Child Node By Name
if (node == null)
    return null;
NodeList childs = node.getChildNodes();
for (int i = 0; i < childs.getLength(); i++) {
    Node child = childs.item(i);
    if (child.getNodeName().equalsIgnoreCase(name)) {
        return child;
return null;
NodegetChildNodeByTagName(Node node, String name)
Gets a child node by the given name.
NodeList children = node.getChildNodes();
if (children != null && children.getLength() > 0) {
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child instanceof Element) {
            Element element = (Element) child;
            if (name.equals(element.getTagName())) {
                return element;
...
NodegetChildNodeByType(Element element, short nodeType)
get Child Node By Type
if (element == null)
    return null;
NodeList nodes = element.getChildNodes();
if (nodes == null || nodes.getLength() < 1)
    return null;
Node node;
String data;
for (int i = 0; i < nodes.getLength(); i++) {
...