get Next Sibling XML Element - Android XML

Android examples for XML:XML Element

Description

get Next Sibling XML Element

Demo Code


//package com.java2s;

import org.w3c.dom.Element;

import org.w3c.dom.Node;

public class Main {
    public static Element getNextSiblingElement(Element element) {
        Element resultElement = null;

        try {//  ww w  . j  a  v a 2 s .c om
            Node node = element.getNextSibling();
            while (node != null) {
                if (node.getNodeType() == Element.ELEMENT_NODE) {
                    resultElement = (Element) node;
                    break;
                }
                node = node.getNextSibling();
            }
        } catch (Throwable t) {
            //t.printStackTrace();
            resultElement = null;
        }
        return resultElement;
    }
}

Related Tutorials