Java XML Node Parent previousSiblingElement(Node node)

Here you can find the source of previousSiblingElement(Node node)

Description

previous Sibling Element

License

Open Source License

Declaration

public static Element previousSiblingElement(Node node) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2008 Red Hat, Inc.//from   w ww .  j ava  2 s .c o  m
 * 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
 *
 * Contributors:
 *     Red Hat, Inc. - initial API and implementation
 ******************************************************************************/

import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class Main {
    public static Element previousSiblingElement(Node node) {
        for (Node tempNode = node.getPreviousSibling(); tempNode != null; tempNode = tempNode
                .getPreviousSibling()) {
            if (tempNode.getNodeType() == Node.ELEMENT_NODE) {
                return (Element) tempNode;
            }
        }
        return null;
    }
}

Related

  1. isAncestorOf(Node node, Node descendant)
  2. isAnyNodeAncestorOf(ArrayList ancestorNodes, Node node)
  3. isDescendant(Node test, Node target)
  4. isDescendantOrSelf(Node ctx, Node descendantOrSelf)
  5. isDescendantOrSelf(Node ctx, Node descendantOrSelf)
  6. resolveLeafNodeValue(Node node)