Get the next sibling XML element. - Java XML

Java examples for XML:DOM Element

Description

Get the next sibling XML element.

Demo Code


//package com.java2s;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class Main {
    /**//from   w w  w. j av  a2 s. co  m
     * Get the next sibling element.
     * 
     * @param node The start node.
     * @return The next sibling element or {@code null}.
     */
    public static Element getNextSiblingElement(Node node) {
        Node n = node.getNextSibling();
        while (n != null && n.getNodeType() != Node.ELEMENT_NODE) {
            n = n.getNextSibling();
        }

        return (Element) n;
    }
}

Related Tutorials