Here you can find the source of getElementsByTagName(Document doc, String tagName)
public static Node[] getElementsByTagName(Document doc, String tagName)
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static Node[] getElementsByTagName(Document doc, String tagName) { try {// ww w. j av a2 s . c o m NodeList list = doc.getElementsByTagName(tagName); int length = list.getLength(); if (length > 0) { Node[] array = new Node[length]; for (int i = 0; i < length; i++) { array[i] = list.item(i); } return array; } return null; } catch (Exception ex) { throw new RuntimeException(ex); } } }