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 {
    /**
     * Method to get the depth of a XML Element.
     * @param element the XML Element.
     * @return the int depth of the XML Element.
     */
    public static int getDepth(Element element) {
        Node parent = element.getParentNode();
        int depth = 0;
        while (parent != null && parent.getNodeType() == Node.ELEMENT_NODE) {
            depth++;
            parent = parent.getParentNode();
        }
        return depth;
    }
}