-
public class NodeWalkerA utility class that allows the walking of any DOM tree using a stack instead of recursion. As the node tree is walked the next node is popped off of the stack and all of its children are automatically added to the stack to be called in tree order.
Currently this class is not thread safe. It is assumed that only one thread will be accessing the
NodeWalkerat any given time.
-
-
Field Summary
Fields Modifier and Type Field Description private NodecurrentNode
-
Constructor Summary
Constructors Constructor Description NodeWalker(Node rootNode)Starts the Nodetree from the root node.
-
Method Summary
Modifier and Type Method Description NodegetCurrentNode()Return the current node. NodenextNode()Returns the next Nodeon the stack and pushes all of itschildren onto the stack, allowing us to walk the node tree without the useof recursion.voidskipChildren()Skips over and removes from the node stack the children of the last node.When getting a next node from the walker, that node's children areautomatically added to the stack. booleanhasNext()* Returns true if there are more nodes on the current stack. -
-
Constructor Detail
-
NodeWalker
NodeWalker(Node rootNode)
Starts theNodetree from the root node.- Parameters:
rootNode- a org.w3c.dom.Node object.
-
-
Method Detail
-
getCurrentNode
Node getCurrentNode()
Return the current node.
-
nextNode
Node nextNode()
Returns the next
Nodeon the stack and pushes all of itschildren onto the stack, allowing us to walk the node tree without the useof recursion. If there are no more nodes on the stack then null isreturned.
-
skipChildren
void skipChildren()
Skips over and removes from the node stack the children of the last node.When getting a next node from the walker, that node's children areautomatically added to the stack. You can call this method to remove thosechildren from the stack.
This is useful when you don't want to process deeper into the current pathof the node tree but you want to continue processing sibling nodes.
-
hasNext
boolean hasNext()
* Returns true if there are more nodes on the current stack.
-
-
-
-