public class XMLIterator extends java.lang.Object implements java.util.Iterator<Content>
hasNext()
, next()
and remove()
methods. XMLIterator performs a pre-order traversal of the Document tree,
that is, it visits each parent node, then the contents of the parent, in
the order that the contents were added. This is also known as visiting
the tree in document order.
XMLIterator may be supplied with a Filter upon creation, in which case
the next()
method will only visit those nodes that are
accepted by the Filter, although all nodes in the tree will be traversed,
while searching for acceptable nodes. After each call to
next()
, it is legal to remove the current node from the tree,
which will also remove any dependent contents. Removing a node does not
affect the traversal of the tree; in particular, the descendants of any
removed nodes will still be traversed.
If created with the notRoot flag set, iteration will commence with the successors of the starting node. This allows client programs to iterate over the descendants of a node, excluding the node itself. If both the notRoot flag and a Filter are supplied, traversal will commence with the successors of the starting node, but only nodes satisfying the Filter will actually be visited.
Modifier and Type | Field and Description |
---|---|
private Content |
current
The currently visited node.
|
private Filter |
filter
The Filter used to select which Content nodes to visit, while
traversing the XML tree.
|
private java.util.List<Content> |
open
The open list of future nodes to traverse.
|
Constructor and Description |
---|
XMLIterator(Content node)
Creates a XMLIterator to traverse an XML tree.
|
XMLIterator(Content node,
boolean notRoot)
Creates a XMLIterator to traverse all of the descendants of a node.
|
XMLIterator(Content node,
Filter filter)
Creates a XMLIterator to traverse an XML tree using a Filter.
|
XMLIterator(Content node,
Filter filter,
boolean notRoot)
Creates a XMLIterator to traverse the descendants of a node using
a Filter.
|
Modifier and Type | Method and Description |
---|---|
boolean |
hasNext()
Reports whether this XMLIterator has further nodes to visit.
|
Content |
next()
Advances this XMLIterator to the next node and returns this node.
|
void |
remove()
Removes the current node.
|
private void |
seek()
Secret method to seek the next Content node that is accepted by a
Filter.
|
private Content current
next()
has selected the node and
updated the open list of future nodes to traverse.private Filter filter
private java.util.List<Content> open
public XMLIterator(Content node)
iterator()
method.node
- the root of the XML tree.public XMLIterator(Content node, boolean notRoot)
descendants()
method. It is used during XPath searching.node
- the root of the XML tree.notRoot
- a flag indicating that the root is not included.public XMLIterator(Content node, Filter filter)
iterator(Filter)
method.node
- the root of the XML tree.filter
- a Filter to apply.public XMLIterator(Content node, Filter filter, boolean notRoot)
descendants(Filter)
method.node
- the root of an XML tree.filter
- a Filter to apply.notRoot
- a flag indicating that the root is not included.private void seek()
next()
, to seek
the next acceptable node. It repeatedly expands the first node on
the open list until that node, or one of its children, siblings, etc.
is accepted by the Filter, or the open list is empty.public boolean hasNext()
hasNext
in interface java.util.Iterator<Content>
public Content next()
next
in interface java.util.Iterator<Content>
public void remove() throws java.lang.IllegalStateException
next()
.
If remove()
is called before the first node is visited
using next()
, or if remove()
is called more
than once without an intervening next()
, this method
throws an IllegalStateException.remove
in interface java.util.Iterator<Content>
java.lang.IllegalStateException
- if there is no current node.