Java XML Node Parent getParent(Node target)

Here you can find the source of getParent(Node target)

Description

get Parent

License

Open Source License

Declaration

private static Element getParent(Node target) 

Method Source Code

//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;
    }
}

Related

  1. getFirstValidNode(Node node)
  2. getParent(Element elem)
  3. getParent(Element elem)
  4. getParent(final Node n)
  5. getParent(Node node)
  6. getParentElement(Element element)
  7. getParentElement(Element element)
  8. getParentElement(final Node node)
  9. getParentElement(Node node)