Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class Main {
    public static Element getElement(Element root, String name) throws Exception {
        NodeList elements = root.getElementsByTagName(name);
        if (elements.getLength() > 0) {
            return (Element) elements.item(0);
        }
        throw new Exception("Child element '" + name + "' to parent " + root.getNodeName() + " not found.");
    }
}