Java XML First Child Element getFirstChildElement(Node parent)

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

Description

Returns a node's first child node that is an element.

License

Apache License

Parameter

Parameter Description
parent a parameter

Return

first child element, or null

Declaration

public static Element getFirstChildElement(Node parent) 

Method Source Code


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

import org.w3c.dom.*;

public class Main {
    /**//from   w w  w  . j  av  a  2  s.co m
     * Returns a node's first child node that is an element.
     * @param parent
     * @return first child element, or null
     */
    public static Element getFirstChildElement(Node parent) {
        NodeList children = parent.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node n = children.item(i);
            if (n.getNodeType() == Node.ELEMENT_NODE) {
                return (Element) n;
            }
        }
        return null;
    }
}

Related

  1. getFirstChildElement(Node parent)
  2. getFirstChildElement(Node parent)
  3. getFirstChildElement(Node parent)
  4. getFirstChildElement(Node parent)
  5. getFirstChildElement(Node parent)
  6. getFirstChildElement(Node rootNode)
  7. getFirstChildElement(Node start)
  8. getFirstChildElementByLocalName(Element parentElem, String localName)
  9. getFirstChildElementByName(Element parent, String tagName)