Java tutorial
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { /** * Returns the first direct child element for the given parent node, which * matches the given tagName (probably faster than retrieving all children first). * @param parent the parent node under which to search for the element * @param tagName the tag name of the element to find * @return Element - the first found Element or null if no such Element is present */ public static Element findFirstChildElement(Node parent, String tagName) { Node n = parent.getFirstChild(); do { if ((n.getNodeType() == Node.ELEMENT_NODE) && (n.getNodeName().equals(tagName))) { return (Element) n; } // Android Workaround try { n = n.getNextSibling(); } catch (IndexOutOfBoundsException e) { n = null; } } while (n != null); return null; } }