Java XML Child Node Get getChildElements(Node node)

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

Description

Return a list of child element types of the provided node.

License

Open Source License

Declaration

public static List<Element> getChildElements(Node node) 

Method Source Code

//package com.java2s;
/*//  w  w w  . j  a  va  2s .  com
 *   Copyright 2017 The Portico Project
 *
 *   This file is part of portico.
 *
 *   portico is free software; you can redistribute it and/or modify
 *   it under the terms of the Common Developer and Distribution License (CDDL) 
 *   as published by Sun Microsystems. For more information see the LICENSE file.
 *   
 *   Use of this software is strictly AT YOUR OWN RISK!!!
 *   If something bad happens you do not have permission to come crying to me.
 *   (that goes for your lawyer as well)
 *
 */

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 child element types of the provided node. If the node has no children
     * or none of the children are element nodes, an empty list is returned.
     */
    public static List<Element> getChildElements(Node node) {
        NodeList list = node.getChildNodes();
        ArrayList<Element> elements = new ArrayList<Element>();
        for (int i = 0; i < list.getLength(); i++) {
            Node temp = list.item(i);
            if (temp.getNodeType() == Node.ELEMENT_NODE)
                elements.add((Element) temp);
        }

        return elements;
    }
}

Related

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