Here you can find the source of isDescendant(Node testNode, Node compareToNode)
public static boolean isDescendant(Node testNode, Node compareToNode)
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Node; public class Main { public static boolean isDescendant(Node testNode, Node compareToNode) { if (testNode != null && compareToNode != null) { while (testNode.getParentNode() != null) { if (testNode.getParentNode() == compareToNode) { return true; }/*w w w. ja v a 2 s.c o m*/ testNode = testNode.getParentNode(); } } return false; } }