Java XML Child Node Get getChildElements(Node parent)

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

Description

returns List of all direct child elements

License

Common Public License

Declaration

public static List getChildElements(Node parent) 

Method Source Code


//package com.java2s;
/*//from  ww  w  .j a  v a 2  s . c  o  m
 * ====================================================================
 * This software is subject to the terms of the Common Public License
 * Agreement, available at the following URL:
 *   http://www.opensource.org/licenses/cpl.html .
 * Copyright (C) 2003-2004 TONBELLER AG.
 * All Rights Reserved.
 * You must accept the terms of that agreement to use this software.
 * ====================================================================
 *
 * 
 */

import java.util.ArrayList;

import java.util.List;

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

public class Main {
    /**
     * returns List of all direct child elements
     */
    public static List getChildElements(Node parent) {
        ArrayList retVec = new ArrayList();

        NodeList children = parent.getChildNodes();
        for (int i = 0; i < children.getLength(); ++i) {
            if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
                retVec.add(children.item(i));
            }
        }
        return retVec;
    }
}

Related

  1. getChildElements(Node node)
  2. getChildElements(Node node)
  3. getChildElements(Node node)
  4. getChildElements(Node node)
  5. getChildElements(Node node)
  6. getChildElements(Node parent)
  7. getChildElements(Node start)
  8. getChildElements(NodeList list)
  9. getChildNode(Element item, String name)