Here you can find the source of getParentElement(Node node)
public static Element getParentElement(Node node)
//package com.java2s; import org.w3c.dom.Node; import org.w3c.dom.Element; public class Main { public static Element getParentElement(Node node) { Node parent = node.getParentNode(); if (parent == null || parent.getNodeType() != Node.ELEMENT_NODE) { return null; } else {/*w w w . ja va 2 s.c om*/ return (Element) parent; } } }