Java tutorial
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Node; public class Main { /** * Check if a node in the parent hierarchy has the name given in parameter * * @param node * @param string * @return true if the node exists */ public static boolean containsInHierarchy(Node node, String string) { Node parent = node; if (node != null) { do { parent = parent.getParentNode(); } while (parent != null && !parent.getNodeName().equals(string)); } return parent != null; } }