Java XML Child Node Get getChildNode(Node node, String name)

Here you can find the source of getChildNode(Node node, String name)

Description

Returns the first XML child tag with the specified name.

License

Open Source License

Parameter

Parameter Description
node The node to search children of
name The name of the node to search for, case-sensitive.

Return

The child with the specified name, or null if none exists.

Declaration

public static Node getChildNode(Node node, String name) 

Method Source Code

//package com.java2s;

import org.w3c.dom.Node;

public class Main {
    /**/*  w  w  w .  ja  va  2  s  .  c om*/
     * Returns the first XML child tag with the specified name.
     *
     * @param node The node to search children of
     * @param name The name of the node to search for, case-sensitive.
     * @return The child with the specified name, or null if none exists.
     */
    public static Node getChildNode(Node node, String name) {
        Node child = node.getFirstChild();
        while (child != null) {
            if (child.getNodeName().equals(name)) {
                return child;
            }
            child = child.getNextSibling();
        }
        return null;
    }
}

Related

  1. getChildNode(Element item, String name)
  2. getChildNode(Node n, String name)
  3. getChildNode(Node n, String name)
  4. getChildNode(Node node, int index)
  5. getChildNode(Node node, String childName)
  6. getChildNode(Node node, String name)
  7. getChildNode(Node node, String name)
  8. getChildNode(Node node, String nodeName)
  9. getChildNode(Node node, String tag)