Java tutorial
//package com.java2s; /******************************************************************************* * Copyright (c) 2003, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - Initial API and implementation * Angelo Zerr <angelo.zerr@gmail.com> - Jetty packages *******************************************************************************/ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * Return an iterator for the subelements. * * @return java.util.Iterator * @param element * org.w3c.dom.Element * @param name * java.lang.String */ public static Iterator<Node> getNodeIterator(Element element, String name) { List<Node> list = new ArrayList<Node>(); NodeList nodeList = element.getElementsByTagName(name); int length = nodeList.getLength(); for (int i = 0; i < length; i++) list.add(nodeList.item(i)); return list.iterator(); } }