Java XML Child Node Get getChildElements(Node node)

Here you can find the source of getChildElements(Node node)

Description

Return a list of the elements that are direct children of the given node.

License

Open Source License

Declaration

public static List<Element> getChildElements(Node node) 

Method Source Code

//package com.java2s;
// modify it under the terms of the GNU General Public License

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 {
    /** Return a list of the elements that are direct children of the given
     * node.//from ww w. j  a  v  a 2 s .  c o m
     */
    public static List<Element> getChildElements(Node node) {
        NodeList childNodes = node.getChildNodes();
        List result = new ArrayList(childNodes.getLength());
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node oneChild = childNodes.item(i);
            if (oneChild instanceof Element)
                result.add(oneChild);
        }
        return result;
    }
}

Related

  1. getChildElements(final Node parentNode, final String... childNodeNames)
  2. getChildElements(Node element)
  3. getChildElements(Node node)
  4. getChildElements(Node node)
  5. getChildElements(Node node)
  6. getChildElements(Node node)
  7. getChildElements(Node node)
  8. getChildElements(Node node)
  9. getChildElements(Node node)