Java XML First Child Element getFirstChild(Element element)

Here you can find the source of getFirstChild(Element element)

Description

Get the first child element of a document element.

License

LGPL

Parameter

Parameter Description
element the element to get the child element from

Return

the first child element of the given element

Declaration

public static Element getFirstChild(Element element) 

Method Source Code

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

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

public class Main {
    /**/*from ww w .ja va 2  s. com*/
     * Get the first child element of a document element. The method returns null if no child element is available or if
     * the specified element is null.
     *
     * @param element the element to get the child element from
     * @return the first child element of the given element
     */
    public static Element getFirstChild(Element element) {
        if (element == null)
            return null;
        NodeList list = element.getChildNodes();
        for (int i = 0; i < list.getLength(); i++) {
            if (list.item(i) instanceof Element) {
                return (Element) list.item(i);
            }
        }
        return null;
    }
}

Related

  1. getFirstChild(Element e)
  2. getFirstChild(Element e, String nsUri, String local)
  3. getFirstChild(Element elem, String childTag)
  4. getFirstChild(Element element)
  5. getFirstChild(Element element)
  6. getFirstChild(Element element)
  7. getFirstChild(Element element, String child)
  8. getFirstChild(Element element, String namespaceUri, String localName)
  9. getFirstChild(Element element, String tag)