Java XML First Child Element getFirstChildByTagName(Element parent, String tagName)

Here you can find the source of getFirstChildByTagName(Element parent, String tagName)

Description

get First Child By Tag Name

License

LGPL

Declaration

public static Element getFirstChildByTagName(Element parent, String tagName) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import org.w3c.dom.Element;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static Element getFirstChildByTagName(Element parent, String tagName) {
        NodeList nodes = parent.getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(tagName)) {
                return (Element) node;
            }//from  w w  w  .  jav a 2  s.c o  m
        }
        return null;
    }
}

Related

  1. getFirstChild(Node parent)
  2. getFirstChildByName(Element parent, String name)
  3. getFirstChildByNodeName(Node parent, String nodeName)
  4. getFirstChildByNS(Element node, String ns, String localName)
  5. getFirstChildByRegex(Element ele, String pattern)
  6. getFirstChildByTagName(Node parent, String tagName)
  7. getFirstChildByTagNameNS(Node contextNode, String nsuri, String tag)
  8. getFirstChildByType(Element element, int nodeType)
  9. getFirstChildByType(Element element, short nodeType)