Here you can find the source of getFirstChildWithTagName(Node data, String tagName)
Parameter | Description |
---|---|
data | Document or Element whose children shall be examined |
tagName | name of the node to find |
Parameter | Description |
---|---|
NoSuchElementException | if no child node with that name can be found |
public static Element getFirstChildWithTagName(Node data, String tagName) throws NoSuchElementException
//package com.java2s; /*/* w ww. ja v a 2 s .c o m*/ * (c) Kitodo. Key to digital objects e. V. <contact@kitodo.org> * * This file is part of the Kitodo project. * * It is licensed under GNU General Public License version 3 or later. * * For the full copyright and license information, please read the * GPL3-License.txt file that was distributed with this source code. */ import java.util.NoSuchElementException; import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { /** * The function getFirstChildWithTagName() returns the first child node from * a node, identified by its node name. * * @param data * Document or Element whose children shall be examined * @param tagName * name of the node to find * @return first child node with that node name * @throws NoSuchElementException * if no child node with that name can be found */ public static Element getFirstChildWithTagName(Node data, String tagName) throws NoSuchElementException { for (Node element = data.getFirstChild(); element != null; element = element.getNextSibling()) { if (!(element instanceof Element)) { continue; } if (element.getNodeName().equals(tagName)) { return (Element) element; } } throw new NoSuchElementException(tagName); } }