Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * (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) {
        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);
    }
}