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.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static Element findGrandson(Element element, String childName, String grandsonName) {
        Element child = find(element, childName);

        if (child == null) {
            return null;
        }
        return find(child, grandsonName);
    }

    public static Element find(Element element, String name) {
        NodeList children = element.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if ((child instanceof Element) && child.getNodeName().equals(name)) {
                return (Element) child;
            }
        }
        return null;
    }
}