Here you can find the source of getElementsByTagName(Node root, String tagName)
public static List<Node> getElementsByTagName(Node root, String tagName)
//package com.java2s; import java.util.ArrayList; import java.util.List; import org.w3c.dom.Node; public class Main { public static List<Node> getElementsByTagName(Node root, String tagName) { List<Node> nodeList = new ArrayList<>(); if (root != null && root.getChildNodes().getLength() > 0) { int childCount = root.getChildNodes().getLength(); for (int i = 0; i < childCount; i++) { Node node = root.getChildNodes().item(i); if (tagName.equals(node.getNodeName())) { nodeList.add(node);/* ww w .j a v a 2 s .c om*/ } } } return nodeList; } }