Java XML First Child Element getFirstChildElement(Element e)

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

Description

Gets the first child element.

License

Open Source License

Parameter

Parameter Description
e the element.

Return

the first child element.

Declaration

public static Element getFirstChildElement(Element e) 

Method Source Code

//package com.java2s;

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

public class Main {
    /**/*from ww  w  .j  a  v  a  2s . c o m*/
     * Gets the first child element.
     * 
     * @param e the element.
     * @return the first child element.
     */
    public static Element getFirstChildElement(Element e) {
        if (e != null) {
            NodeList children = e.getChildNodes();
            for (int i = 0; i < children.getLength(); i++) {
                Node node = children.item(i);
                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    return (Element) node;
                }
            }
        }
        return null;
    }
}

Related

  1. getFirstChildByTagNameNS(Node contextNode, String nsuri, String tag)
  2. getFirstChildByType(Element element, int nodeType)
  3. getFirstChildByType(Element element, short nodeType)
  4. getFirstChildElement(@Nonnull final Node aStartNode)
  5. getFirstChildElement(Element e)
  6. getFirstChildElement(Element e)
  7. getFirstChildElement(Element ele)
  8. getFirstChildElement(Element elem)
  9. getFirstChildElement(Element elem)