Here you can find the source of getChildElemByTagName(Element parent, String tagName)
public static Element getChildElemByTagName(Element parent, String tagName)
//package com.java2s; /*/*from w ww. j a v a2 s . com*/ * ==================================================================== * This software is subject to the terms of the Common Public License * Agreement, available at the following URL: * http://www.opensource.org/licenses/cpl.html . * Copyright (C) 2003-2004 TONBELLER AG. * All Rights Reserved. * You must accept the terms of that agreement to use this software. * ==================================================================== * * */ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * returns first child element with fitting tag name. */ public static Element getChildElemByTagName(Element parent, String tagName) { NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); ++i) { if (children.item(i).getNodeType() == Node.ELEMENT_NODE) { Element child = (Element) children.item(i); if (child.getTagName().equals(tagName)) return child; } } return null; } }