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