Java tutorial
//package com.java2s; import java.util.function.Consumer; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static void forEachByTagName(Document doc, String tagname, Consumer<Node> action) { NodeList nl = doc.getElementsByTagName(tagname); forEach(nl, action); } public static void forEach(NodeList nl, Consumer<Node> action) { for (int i = 0; i < nl.getLength(); i++) { action.accept(nl.item(i)); } } }