Java XML First Child Element getFirstElementChild(Element elemNode)

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

Description

Returns the first element node within the children of the specified element.

License

Open Source License

Parameter

Parameter Description
elemNode The element whose first element child is to be returned.

Declaration

public static Element getFirstElementChild(Element elemNode) 

Method Source Code

//package com.java2s;
/*--------------------------------------------------------------------------------
 Copyright (C) 2002, 2004 ISOGEN International

 http://www.isogen.com/* w w  w. j a v  a  2  s  . c  o  m*/

 This program 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.

 This program 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 General Public License for more details.

 You should have received a copy of the GNU Lesser General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

 --------------------------------------------------------------------------------*/

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

public class Main {
    /**
     * Returns the first element node within the children of the specified element.
     *
     * @param elemNode The element whose first element child is to be returned.
     */
    public static Element getFirstElementChild(Element elemNode) {
        NodeList nl = elemNode.getChildNodes();
        for (int i = 0; i < nl.getLength(); i++) {
            Node cand = nl.item(i);
            if (cand.getNodeType() == Node.ELEMENT_NODE) {
                return (Element) cand;
            }
        }
        return null;
    }
}

Related

  1. getFirstChildWithTagName(Element parent, String tagName)
  2. getFirstChildWithTagName(Node data, String tagName)
  3. getFirstElement(Element element, String childName)
  4. getFirstElementChild(Element aElement)
  5. getFirstElementChild(Element element)
  6. getFirstElementChild(Element elemNode)
  7. getFirstElementChild(Element parent)
  8. GetFirstElementChild(Element tag)
  9. getFirstElementChild(final Element element, final String namespace, final String localname)