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;

public class Main {
    public static Node getParentById(String id, Node node) {
        Node parent = node.getParentNode();

        while (parent != null) {
            if (parent instanceof Element && id.equalsIgnoreCase(((Element) parent).getAttribute("id"))) {
                return parent;
            } else {
                parent = parent.getParentNode();
            }
        }

        return parent;
    }
}