Here you can find the source of getParent(Node target)
private static Element getParent(Node target)
//package com.java2s; /******************************************************************************* * Copyright (c) 2004, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/* w w w . j av a 2 s . co m*/ * IBM Corporation - initial API and implementation *******************************************************************************/ import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { private static Element getParent(Node target) { Node parent = target.getParentNode(); while (parent != null) { if (parent.getNodeType() == Node.ELEMENT_NODE) return (Element) parent; parent = parent.getParentNode(); } return null; } }