Here you can find the source of isAncestorOf(Node ancestor, Node node)
public static boolean isAncestorOf(Node ancestor, Node node)
//package com.java2s; import org.w3c.dom.Node; public class Main { public static boolean isAncestorOf(Node ancestor, Node node) { while (node != null) { if (node == ancestor) { return true; }//from w ww . j a v a 2 s. co m node = node.getParentNode(); } return false; } }