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

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

Description

Return the child node of the specified node with the specified tag.

License

Open Source License

Parameter

Parameter Description
node The parent DOM node
tag The tag of the node

Return

the child node

Declaration

public static Node getChildNode(Node node, String tag) 

Method Source Code


//package com.java2s;

import org.w3c.dom.*;

public class Main {
    /**/*from  w w  w .ja  va2s .  c  o m*/
     * Return the child node of the specified node with the specified tag.
     *
     * @param node The parent DOM node
     * @param tag The tag of the node
     * @return the child node 
     */
    public static Node getChildNode(Node node, String tag) {
        Node res = null;
        NodeList children = node.getChildNodes();
        int len = (children != null) ? children.getLength() : 0;
        int i = 0;
        while (i < len && res == null) {
            Node child = children.item(i);
            String nodeName = child.getNodeName();
            if (nodeName.equals(tag)) {
                res = child;
            }
            i++;
        }
        return res;
    }
}

Related

  1. getChildNode(Node node, String childName)
  2. getChildNode(Node node, String name)
  3. getChildNode(Node node, String name)
  4. getChildNode(Node node, String name)
  5. getChildNode(Node node, String nodeName)
  6. getChildNode(Node parent, String childName)
  7. getChildNode(Node parent, String tagName)
  8. getChildNode(Node parentNode, String childElementName)
  9. getChildNode(Node root, String childName)