Java XML First Child Element getFirstChildElementByTagName(Element element, String name)

Here you can find the source of getFirstChildElementByTagName(Element element, String name)

Description

get First Child Element By Tag Name

License

Apache License

Declaration

public static Element getFirstChildElementByTagName(Element element, String name) 

Method Source Code

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

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

public class Main {
    public static Element getFirstChildElementByTagName(Element element, String name) {
        boolean found = false;
        Element result = null;//  ww  w.  ja va  2s . c  o  m
        NodeList nl = element.getChildNodes();
        for (int i = 0; i < nl.getLength() && !found; i++) {
            if (nl.item(i) instanceof Element) {
                if (name.equals(nl.item(i).getNodeName())) {
                    result = (Element) nl.item(i);
                    found = true;
                }
            }

        }
        return result;
    }
}

Related

  1. getFirstChildElementByLocalName(Element parentElem, String localName)
  2. getFirstChildElementByName(Element parent, String tagName)
  3. getFirstChildElementByName(Element root, String tagName)
  4. getFirstChildElementByName(final Element parent, final String name)
  5. getFirstChildElementByName(Node node, String name)
  6. getFirstChildElementByTagName(Node element, String tagName)
  7. getFirstChildElementCaseInsensitive(Element root, String elementName)
  8. getFirstChildElementInternal(final Node node, final boolean useNamespaces, final String namespaceURI, final String localName)
  9. getFirstChildElementNode(Node node)