Java XML First Child Element getFirstElement(Element element, String childName)

Here you can find the source of getFirstElement(Element element, String childName)

Description

get First Element

License

Apache License

Declaration

static Element getFirstElement(Element element, String childName) 

Method Source Code

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

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

public class Main {
    static Element getFirstElement(Element element, String childName) {
        NodeList children = element.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if (child instanceof Element && ((Element) child).getTagName().equals(childName)) {
                return (Element) child;
            }// w ww  .  j  a  va2s . c o m
        }
        return null;
    }
}

Related

  1. getFirstChildTextContent(Node node)
  2. getFirstChildTextNodeValue(Node node)
  3. getFirstChildTextValue(Element parent, String childName)
  4. getFirstChildWithTagName(Element parent, String tagName)
  5. getFirstChildWithTagName(Node data, String tagName)
  6. getFirstElementChild(Element aElement)
  7. getFirstElementChild(Element element)
  8. getFirstElementChild(Element elemNode)
  9. getFirstElementChild(Element elemNode)