Java XML First Child Element firstChildByTagName(Node root, String tagName)

Here you can find the source of firstChildByTagName(Node root, String tagName)

Description

first Child By Tag Name

License

Open Source License

Declaration

public static Node firstChildByTagName(Node root, String tagName) 

Method Source Code

//package com.java2s;

import org.w3c.dom.Node;

public class Main {

    public static Node firstChildByTagName(Node root, String tagName) {

        if (root != null && root.getChildNodes().getLength() > 0) {

            int childCount = root.getChildNodes().getLength();
            for (int i = 0; i < childCount; i++) {

                if (tagName.equals(root.getChildNodes().item(i).getNodeName())) {
                    return root.getChildNodes().item(i);
                }/*  w  w w.  ja va 2s.c om*/
            }
        }

        return null;
    }
}

Related

  1. extractFirstChildValue(final Node node)
  2. firstByClass(NodeList childList, String className)
  3. firstChild(Element element, String name)
  4. firstChild(Element element, String name)
  5. firstChildElement(Element element, String childElementName)
  6. firstChildElement(Element parent)
  7. firstChildElement(Node node)
  8. firstChildElement(Node node)