Java XML Node Sibiling getPreviousSiblingElement(Node node)

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

Description

Get the previous sibling element.

License

Apache License

Parameter

Parameter Description
node The start node.

Return

The previous sibling element or null .

Declaration

public static Element getPreviousSiblingElement(Node node) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    /**/*from w w  w  . jav a2 s.  com*/
     * Get the previous sibling element.
     * 
     * @param node The start node.
     * @return The previous sibling element or {@code null}.
     */
    public static Element getPreviousSiblingElement(Node node) {
        Node n = node.getPreviousSibling();
        while (n != null && n.getNodeType() != Node.ELEMENT_NODE) {
            n = n.getPreviousSibling();
        }

        return (Element) n;
    }
}

Related

  1. getNextSiblingElementNS(Node node, String[][] elemNames)
  2. getNextVisibleSiblingElement(Node node)
  3. getPreHomoSibling(Node aNode)
  4. getPreviousSibling(Node node, short nodeType)
  5. getPreviousSiblingByName(Node currentNode, String tagName)
  6. getPreviousSiblingElement(Node node)
  7. getSibling(Node current)
  8. getSiblingValues(Node currentNode, Set siblingTags)