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;
/*/* w  w  w. j  a v a2 s. c om*/
 * Radakan is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Radakan is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Radakan.  If not, see <http://www.gnu.org/licenses/>.
 */

import org.w3c.dom.Node;

public class Main {
    /**
     * 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 && !child.getNodeName().equals(name)) {
            child = child.getNextSibling();
        }
        return child;
    }
}

Related

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