Here you can find the source of getNextNode(Node current)
public static Node getNextNode(Node current)
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Node; public class Main { public static Node getNextNode(Node current) { if (current == null) { System.out.println("NODE IS NULL"); return null; }//from ww w . ja v a2 s . c o m boolean found = false; boolean childVisited = false; while (found != true) { if (current.hasChildNodes() && childVisited == false) { current = current.getFirstChild(); found = true; } else { if (current.getNextSibling() != null) { current = current.getNextSibling(); found = true; childVisited = false; } else { if (current.getParentNode() != null) current = current.getParentNode(); else { return null; } childVisited = true; } } } return current; } }