Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.w3c.dom.*;

public class Main {

    public static Element getGrandSonElementByTagName(Element element, String parentName, String eleName) {

        NodeList nl = element.getElementsByTagName(parentName);
        if (null == nl) {
            return null;
        }
        Node item = nl.item(0);
        return getChildElementByTagName((Element) item, eleName);
    }

    public static Element getChildElementByTagName(Element ele, String childEleName) {

        NodeList nl = ele.getChildNodes();
        for (int i = 0; i < nl.getLength(); i++) {
            Node node = nl.item(i);
            if (node instanceof Element && childEleName.equals(node.getNodeName())
                    || childEleName.equals(node.getLocalName())) {
                return (Element) node;
            }
        }
        return null;
    }
}