Here you can find the source of getElementsWithName(Document doc, String name)
public static Element[] getElementsWithName(Document doc, String name)
//package com.java2s; //License from project: Apache License import org.w3c.dom.*; import java.util.*; public class Main { /**//from w w w . ja v a 2s . c o m Write all links if it has a CatalogID and recurse to contained ids */ public static Element[] getElementsWithName(Document doc, String name) { NodeList nodes = doc.getElementsByTagName(name); int n = nodes.getLength(); List holder = new ArrayList(n); for (int i = 0; i < n; i++) { Node item = nodes.item(i); if (item.getNodeType() == Node.ELEMENT_NODE) holder.add(item); } Element[] ret = new Element[holder.size()]; holder.toArray(ret); return (ret); } /** Write all links if it has a CatalogID and recurse to contained ids */ public static Element[] getElementsWithName(Element doc, String name) { NodeList nodes = doc.getElementsByTagName(name); int n = nodes.getLength(); List holder = new ArrayList(n); for (int i = 0; i < n; i++) { Node item = nodes.item(i); if (item.getNodeType() == Node.ELEMENT_NODE) holder.add(item); } Element[] ret = new Element[holder.size()]; holder.toArray(ret); return (ret); } }