Java tutorial
//package com.java2s; // Use is subject to license terms. import org.w3c.dom.*; public class Main { /** * Find the first child Element matching the given tag name. Only searches * 1st-level children; not a recursive search. Null if not found. */ public static Element findChildElementMatching(Node root, String tagName) { return (Element) findChildNodeMatching(root, tagName, Node.ELEMENT_NODE); } /** * Find the first child node matching the given tag name. Only searches * 1st-level children; not a recursive search. Null if not found. */ public static Node findChildNodeMatching(Node root, String tagName, short nodeType) { Node childNode = root.getFirstChild(); while (childNode != null) { if (childNode.getNodeType() == nodeType) { if (tagName.equals(childNode.getNodeName())) { return childNode; } } childNode = childNode.getNextSibling(); } return null; } }