Java XML First Child Element getFirstElementChild(Element aElement)

Here you can find the source of getFirstElementChild(Element aElement)

Description

Gets the first DOM Element Node of the aElement DOM Element.

License

Open Source License

Parameter

Parameter Description
aElement Element to scan for the first element.

Return

Found DOM Element Node if found; null otherwise.

Declaration

public static Element getFirstElementChild(Element aElement) 

Method Source Code

//package com.java2s;
/***********************************************************
 Copyright (C) 2004 VeriSign, Inc.//from  ww w .  jav  a2s  . c o  m
    
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.
    
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 Lesser General Public License for more details.
    
 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    
 http://www.verisign.com/nds/naming/namestore/techdocs.html
 ***********************************************************/

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

public class Main {
    /**
     * Gets the first DOM Element Node of the <code>aElement</code> DOM Element.
     * 
     * @param aElement
     *            Element to scan for the first element.
     * @return Found DOM Element Node if found; <code>null</code> otherwise.
     */
    public static Element getFirstElementChild(Element aElement) {
        NodeList children = aElement.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. getFirstChildTextNodeValue(Node node)
  2. getFirstChildTextValue(Element parent, String childName)
  3. getFirstChildWithTagName(Element parent, String tagName)
  4. getFirstChildWithTagName(Node data, String tagName)
  5. getFirstElement(Element element, String childName)
  6. getFirstElementChild(Element element)
  7. getFirstElementChild(Element elemNode)
  8. getFirstElementChild(Element elemNode)
  9. getFirstElementChild(Element parent)