Java XML Child Get getChildElements(Element parentElement)

Here you can find the source of getChildElements(Element parentElement)

Description

Returns a list of child nodes of parentElement that are Element s.

License

Open Source License

Parameter

Parameter Description
parentElement the element to find the children of

Return

a node list of the children of parentElement

Declaration

protected static List<Element> getChildElements(Element parentElement) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007 Intel Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from  w  w  w . j  av  a  2 s . c  om*/
 *    Dennis Ushakov, Intel - Initial API and Implementation
 *    Oleg Danilov, Intel
 *
 *******************************************************************************/

import java.util.ArrayList;

import java.util.List;

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

public class Main {
    /**
     * Returns a list of child nodes of <code>parentElement</code> that are
     * {@link Element}s. Returns an empty list if no elements are found.
     * 
     * @param parentElement
     *            the element to find the children of
     * @return a node list of the children of parentElement
     */
    protected static List<Element> getChildElements(Element parentElement) {
        List<Element> list = new ArrayList<Element>();

        if (parentElement != null) {
            NodeList children = parentElement.getChildNodes();
            for (int i = 0; i < children.getLength(); i++) {
                if (children.item(i).getNodeType() == Node.ELEMENT_NODE)
                    list.add((Element) children.item(i));
            }
        }

        return list;
    }
}

Related

  1. getChildElements(Element parent)
  2. getChildElements(Element parent)
  3. getChildElements(Element parent)
  4. getChildElements(Element parent)
  5. getChildElements(Element parent)
  6. getChildElements(Element parentElement)
  7. getChildElements(Element parentElement, String childElementTagName)
  8. getChildElements(Element parentNode)
  9. getChildElements(Element root, String name, boolean mandatory)