Java XML Node Next getNextElement(Node node)

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

Description

Get a sibling XML element of a given node.

License

BSD License

Parameter

Parameter Description
node the pareent XML node

Return

Node the next XML sibling element.

Declaration

public static Node getNextElement(Node node) 

Method Source Code

//package com.java2s;
/*L/*  w w w .j av  a  2 s  .  c  o  m*/
 * Copyright SAIC, SAIC-Frederick.
 *
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/caadapter/LICENSE.txt for details.
 */

import org.w3c.dom.Node;

public class Main {
    /**
     * Get a sibling XML element of a given node. For example, with the following structure
     *   <node1>
     *     <node2>
     *     <node3>
     *   getNextElement(node2) will return a reference to <node3>
     *
     * @param node the pareent XML node
     * @return Node the next XML sibling element.
     */
    public static Node getNextElement(Node node) {
        Node child = node.getNextSibling();
        if (child == null)
            return null;
        if (child.getNodeType() == Node.ELEMENT_NODE)
            return child;
        while (child != null) {
            if (child.getNodeType() == Node.ELEMENT_NODE)
                return child;
            child = child.getNextSibling();
        }
        return null;
    }
}

Related

  1. getNextComment(Node element)
  2. getNextComment(Node element)
  3. getNextElement(Node el)
  4. getNextElement(Node node)
  5. getNextElement(Node node)
  6. getNextElementNode(Node node)
  7. getNextElementNode(Node node)
  8. getNextNode(Node current)
  9. getNextNodeByName(Node currentNode, String tagName)