Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.IOException;

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

public class Main {
    private static Element findElement(Element root, String tag) throws IOException {
        NodeList elements = root.getElementsByTagName(tag);

        if (elements.getLength() == 0) {
            throw new IOException("Tag " + tag + " was expected and not found.");
        } else if (elements.getLength() != 1) {
            throw new IOException("Tag " + tag + " cannot have multiple definitions.");
        }

        return (Element) elements.item(0);
    }
}