Java XML First Child Element getFirstChildOfTagName(Element elem, String name)

Here you can find the source of getFirstChildOfTagName(Element elem, String name)

Description

get First Child Of Tag Name

License

Open Source License

Declaration

static Element getFirstChildOfTagName(Element elem, String name) 

Method Source Code

//package com.java2s;
/*  it under the terms of the GNU General Public License as published by    */

import org.w3c.dom.Element;
import org.w3c.dom.Node;

import org.w3c.dom.NodeList;

public class Main {
    static Element getFirstChildOfTagName(Element elem, String name) {
        NodeList nodeList = elem.getChildNodes();

        if (nodeList == null) {
            return null;
        }// www  .j  av  a2s  .  c  o m

        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);

            if (node instanceof Element) {
                elem = (Element) node;
                if (elem.getTagName().equals(name)) {
                    return elem;
                }
            }
        }

        return null;
    }
}

Related

  1. getFirstChildElmtByTagAndAttribut(Node aNode, String aTagName, String aAttrId, String aAttrValue)
  2. getFirstChildNamed(Element elem, String childName)
  3. getFirstChildNamed(Node node, String name)
  4. getFirstChildNode(Node parentNode, String childNodeName)
  5. getFirstChildNodeWithName(String nodeName, Node parentNode)
  6. getFirstChildOfType(final Element elParent, final String childTag)
  7. getFirstChildTag(Element el, String tag)
  8. getFirstChildText(@Nullable final Node aStartNode)
  9. getFirstChildText(Node aNode)