Class Selection
java.lang.Object
org.libxmq.Selection
The nodes selected by an xpath, returned by
Query.select(String). Like
XMQSelection in the C api: the xpath is evaluated once, when the selection is created,
and the nodes come in document order. A selection is Iterable, so it is used in a
for loop, and each call to iterator() starts from the first node:
for (XMQNode book : query.select("//book"))
{
// use book, an exception thrown here needs no cleanup
}
The nodes belong to the document, which must not be changed while the selection is used.-
Method Summary
Modifier and TypeMethodDescriptionat(int index) Get a node by its position, like xmqSelectionAt.intcount()The number of nodes, like xmqSelectionCount.booleanisEmpty()Is the selection empty?iterator()Iterate over the selected nodes, from the first node, like xmqSelectionNext.nodes()The selected nodes as an unmodifiable list.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Method Details
-
count
public int count()The number of nodes, like xmqSelectionCount.- Returns:
- The number of selected nodes.
-
at
Get a node by its position, like xmqSelectionAt.- Parameters:
index- The position, 0 is the first node.- Returns:
- The node.
- Throws:
IndexOutOfBoundsException- if index is negative or not less than count().
-
isEmpty
public boolean isEmpty()Is the selection empty?- Returns:
- True if no node was selected.
-
nodes
-
iterator
-