Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Node;

public class Main {
    /**
     * get the node following the node in parameter
     * 
     * @param n
     *            the n
     * @return the node
     */
    public static Node next(Node n) {
        if (n == null) {
            return null;
        }
        Node currentNode = n;
        if (currentNode.getChildNodes().getLength() > 0) {
            currentNode = currentNode.getFirstChild();
        } else {
            if (currentNode.getNextSibling() != null) {
                currentNode = currentNode.getNextSibling();
            } else {
                Node oldCurrentNode = currentNode;
                currentNode = currentNode.getParentNode().getNextSibling();
                while (oldCurrentNode != null && currentNode == null) {
                    oldCurrentNode = oldCurrentNode.getParentNode();
                    if (oldCurrentNode != null) {
                        currentNode = oldCurrentNode.getNextSibling();
                    }
                }
            }
        }
        return currentNode;
    }
}