Java tutorial
//package com.java2s; /* * XMLUtils.java * * Copyright (c) 1998 - 2006 BusinessTechnology, Ltd. * All rights reserved * * This program is the proprietary and confidential information * of BusinessTechnology, Ltd. and may be used and disclosed only * as authorized in a license agreement authorizing and * controlling such use and disclosure * * Millennium ERP system. * */ import org.w3c.dom.Element; import org.w3c.dom.Node; import java.util.LinkedList; import java.util.List; public class Main { /** * Return a List of Element objects that have the given name and are immediate children of the * given element; if name is null, all child elements will be included. */ public static List<Element> childElementList(Element element, String childElementName) { if (element == null) return null; List<Element> elements = new LinkedList<Element>(); Node node = element.getFirstChild(); if (node != null) { do { if (node.getNodeType() == Node.ELEMENT_NODE && (childElementName == null || childElementName.equals(node.getNodeName()))) { Element childElement = (Element) node; elements.add(childElement); } } while ((node = node.getNextSibling()) != null); } return elements; } }