Here you can find the source of getChildElements(Element parentNode)
Parameter | Description |
---|---|
parentNode | a parameter |
Parameter | Description |
---|---|
DOMException | an exception |
public static List<Element> getChildElements(Element parentNode) throws DOMException
//package com.java2s; import java.util.ArrayList; import java.util.List; import org.w3c.dom.DOMException; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**/*from w w w . j a v a 2s . c om*/ * return all the child Elements of given Element; it's not deep search, so only the first generation children list is scanned. * * @param parentNode * @return an empty list if nothing found * @throws DOMException */ public static List<Element> getChildElements(Element parentNode) throws DOMException { if (parentNode == null) { return null; } List<Element> resultList = new ArrayList<Element>(); NodeList childNodes = parentNode.getChildNodes(); if (childNodes != null) { for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE && node.getParentNode() == parentNode) { resultList.add((Element) node); } } } return resultList; } }