Here you can find the source of getFirstLevelChildElements(Element parent)
Parameter | Description |
---|---|
parent | Parent Element |
public static final List<Element> getFirstLevelChildElements(Element parent)
//package com.java2s; 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 { /**/*from w w w. j av a 2s .c o m*/ * Get all the first level child elements. * * @param parent * Parent Element * * @return List of all the child Elements. */ public static final List<Element> getFirstLevelChildElements(Element parent) { NodeList nodeList = parent.getChildNodes(); ArrayList<Element> childList = new ArrayList<Element>(nodeList.getLength()); Node childNode = parent.getFirstChild(); while (childNode != null) { if (childNode.getNodeType() == Node.ELEMENT_NODE) { childList.add((Element) childNode); } childNode = childNode.getNextSibling(); } return childList; } }