Java XML Element Sibling getNextElementSibling(Element aElement)

Here you can find the source of getNextElementSibling(Element aElement)

Description

Gets the next sibling Element of a provided Element.

License

Open Source License

Parameter

Parameter Description
aElement Element to start scan for the next Element.

Return

Found DOM Element Node if found; null otherwise.

Declaration

public static Element getNextElementSibling(Element aElement) 

Method Source Code

//package com.java2s;
/***********************************************************
 Copyright (C) 2004 VeriSign, Inc.//from w  w  w.  j  a v  a2s.com

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

 http://www.verisign.com/nds/naming/namestore/techdocs.html
 ***********************************************************/

import org.w3c.dom.*;

public class Main {
    /**
     * Gets the next sibling Element of a provided Element.
     * 
     * @param aElement
     *            Element to start scan for the next Element.
     * @return Found DOM Element Node if found; <code>null</code> otherwise.
     */
    public static Element getNextElementSibling(Element aElement) {
        Element theSibling = null;
        Node theCurrNode = aElement;

        while ((theCurrNode != null) && (theSibling == null)) {
            theCurrNode = theCurrNode.getNextSibling();

            if ((theCurrNode != null)
                    && (theCurrNode.getNodeType() == Node.ELEMENT_NODE)) {
                theSibling = (Element) theCurrNode;
            }
        }

        return theSibling;
    }
}

Related

  1. countPrecedingSiblingsOfType(Element inElem)
  2. getNextSibling(Element element)
  3. getNextSibling(Element h2)
  4. getNextSibling(Element node, String name)
  5. getNextSiblingElement(Element el)