int nodeType = node.getNodeType(); switch (nodeType) { case Node.ATTRIBUTE_NODE: return ((Attr) node).getOwnerElement(); case Node.TEXT_NODE: return (Element) ((Text) node).getParentNode(); case Node.CDATA_SECTION_NODE: return (Element) ((CDATASection) node).getParentNode(); ...