Java XML First Child Element getDirectChildElements(Element parent)

Here you can find the source of getDirectChildElements(Element parent)

Description

Returns a collection of direct child Elements

License

Open Source License

Parameter

Parameter Description
parent the parent whose direct children will be processed

Return

a collection of all child Elements

Declaration

public static ArrayList<Element> getDirectChildElements(Element parent) 

Method Source Code

//package com.java2s;
import java.util.ArrayList;

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

public class Main {
    /**/*from   w  ww . ja  v  a2s  . c om*/
     * Returns a collection of direct child Elements
     * @param parent the parent whose direct children will be processed
     * @return a collection of all child Elements
     */
    public static ArrayList<Element> getDirectChildElements(Element parent) {
        ArrayList<Element> result = new ArrayList<Element>();

        for (Node child = parent.getFirstChild(); child != null; child = child
                .getNextSibling()) {
            if (child instanceof Element) {
                result.add((Element) child);
            }
        }

        return result;
    }
}

Related

  1. firstNamedChild(Element el, String lName)
  2. firstTextChild(Element el)
  3. getDirectChild(Node fNode, String localName, String namespace)
  4. getDirectChild(Node fNode, String localName, String namespace)
  5. getDirectChildElement(Element p_rootElement, String p_elementName)
  6. getDirectChildElements(Node fNode, String localName, String namespace)
  7. getDirectChildElementsByTag(Element node, String tag)
  8. getDirectChildElementValue(Element p_rootElement, String p_elementName)
  9. getDirectChildElementValues(Element p_rootElement, String p_elementName)