Here you can find the source of getAncestorNode(Node visualNode, String tagName)
static public Node getAncestorNode(Node visualNode, String tagName)
//package com.java2s; /******************************************************************************* * Copyright (c) 2007-2014 Red Hat, Inc. * Distributed under license by Red Hat, Inc. All rights reserved. * This program is 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 * * Contributor:// www .j a v a2 s . c om * Red Hat, Inc. - initial API and implementation ******************************************************************************/ import org.w3c.dom.Node; public class Main { static public Node getAncestorNode(Node visualNode, String tagName) { if (tagName == null) return null; Node element = visualNode; while (true) { if (tagName.equalsIgnoreCase(element.getNodeName())) { return element; } element = element.getParentNode(); if (element == null) { break; } } return null; } }