Java tutorial
//package com.java2s; //License from project: Apache License import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static Element getChildByTagName(Element element, String tagName) { Element result = null; NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node n = childNodes.item(i); if (!(n instanceof Element)) { continue; } if (((Element) n).getTagName().equals(tagName)) { if (result != null) { throw new RuntimeException("Too many elements with tag name " + tagName); } result = (Element) n; } } return result; } }