Java examples for XML:XML Element Child
Obtain all child XML elements.
/******************************************************************************* * Copyright (c) 2015-2016 Oak Ridge National Laboratory. * 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 *******************************************************************************/ import java.io.InputStream; import java.util.Iterator; import java.util.Optional; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main{ /** Obtain all child elements. * @param parent Parent node/* w ww.jav a 2 s . co m*/ * @return {@link Iterable} for child elements */ public static Iterable<Element> getChildElements(final Node parent) { return () -> new ElementIterator(parent); } /** Obtain all child elements with given name. * @param parent Parent node * @param name Name of child elements * @return {@link Iterable} for matching child elements */ public static Iterable<Element> getChildElements(final Node parent, final String name) { return () -> new NamedElementIterator(parent, name); } }