Java XML First Child Element getFirstChildElement(Element ele)

Here you can find the source of getFirstChildElement(Element ele)

Description

a utility method for finding the first child XML element of given XML element

License

Open Source License

Parameter

Parameter Description
ele a parameter

Declaration

public static Element getFirstChildElement(Element ele) 

Method Source Code

//package com.java2s;

import org.w3c.dom.Element;

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

public class Main {
    /**//ww  w .j a va2  s.  c  o m
     * a utility method for finding the first child XML element of given XML element
     * 
     * @param ele
     * @return
     */
    public static Element getFirstChildElement(Element ele) {
        Element resultEle = null;
        NodeList childNodes = ele.getChildNodes();
        if (childNodes != null) {
            for (int i = 0; i < childNodes.getLength(); i++) {
                Node node = childNodes.item(i);
                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    resultEle = (Element) node;
                    break;
                }
            }
        }
        return resultEle;
    }
}

Related

  1. getFirstChildByType(Element element, short nodeType)
  2. getFirstChildElement(@Nonnull final Node aStartNode)
  3. getFirstChildElement(Element e)
  4. getFirstChildElement(Element e)
  5. getFirstChildElement(Element e)
  6. getFirstChildElement(Element elem)
  7. getFirstChildElement(Element elem)
  8. getFirstChildElement(Element elem)
  9. getFirstChildElement(Element element)