Java tutorial
//package com.java2s; /* * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. * * Distributable under LGPL license. * See terms of license at gnu.org. */ import org.w3c.dom.*; public class Main { /** * Returns the child element with the specified tagName for the specified * parent element. * @param parent The parent whose child we're looking for. * @param tagName the name of the child to find * @return The child with the specified name or null if no such child was * found. * @throws NullPointerException if parent or tagName are null */ public static Element findChild(Element parent, String tagName) { if (parent == null || tagName == null) throw new NullPointerException( "Parent or tagname were null! " + "parent = " + parent + "; tagName = " + tagName); NodeList nodes = parent.getChildNodes(); Node node; int len = nodes.getLength(); for (int i = 0; i < len; i++) { node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE && ((Element) node).getNodeName().equals(tagName)) return (Element) node; } return null; } }