Java XML First Child Element getFirstChildElement(Node node)

Here you can find the source of getFirstChildElement(Node node)

Description

Get the first child node that is an element node.

License

Apache License

Parameter

Parameter Description
node The node whose children should be iterated.

Return

The first child element or null .

Declaration

public static Element getFirstChildElement(Node node) 

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 {
    /**//  w ww .j  av a2s . co  m
     * Get the first child node that is an element node.
     * 
     * @param node The node whose children should be iterated.
     * @return The first child element or {@code null}.
     */
    public static Element getFirstChildElement(Node node) {
        NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
                return (Element) children.item(i);
            }
        }

        return null;
    }
}

Related

  1. getFirstChildElement(Node node)
  2. getFirstChildElement(Node node)
  3. getFirstChildElement(Node node)
  4. getFirstChildElement(Node node)
  5. getFirstChildElement(Node node)
  6. getFirstChildElement(Node node)
  7. getFirstChildElement(Node node, String tag)
  8. getFirstChildElement(Node parent)
  9. getFirstChildElement(Node parent)