Java tutorial
//package com.java2s; import java.util.ArrayList; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** */ public static Element getElement(String name, int index, Element parent) { ArrayList<Element> toReturn = getElementsByTag(name, parent); if (index > toReturn.size() - 1) { return null; } return toReturn.get(index); } /** */ public static ArrayList<Element> getElementsByTag(String tag, Element searchIn) { NodeList list = searchIn.getElementsByTagName(tag); ArrayList<Element> toReturn = new ArrayList<Element>(); for (int i = 0; i < list.getLength(); i++) { Node n = list.item(i); if (!(n instanceof Element)) { continue; } toReturn.add((Element) n); } return toReturn; } }