Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Iterator; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static Element getElement(Document doc, String tagName, int index) { NodeList rows = doc.getDocumentElement().getElementsByTagName(tagName); return (Element) rows.item(index); } public static Iterator getElementsByTagName(Element element, String tag) { ArrayList<Element> children = new ArrayList<Element>(); if (element != null && tag != null) { NodeList nodes = element.getElementsByTagName(tag); for (int i = 0; i < nodes.getLength(); i++) { Node child = nodes.item(i); children.add((Element) child); } } return children.iterator(); } }