Java tutorial
//package com.java2s; import org.w3c.dom.*; public class Main { public static Node up(Node node, String element) { while (node != null && node.getNodeName() != null && !node.getNodeName().equalsIgnoreCase(element)) { node = node.getParentNode(); } return node; } }