Class Selection

java.lang.Object
org.libxmq.Selection
All Implemented Interfaces:
Iterable<XMQNode>

public final class Selection extends Object implements Iterable<XMQNode>
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 Details

    • count

      public int count()
      The number of nodes, like xmqSelectionCount.
      Returns:
      The number of selected nodes.
    • at

      public XMQNode at(int index)
      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

      public List<XMQNode> nodes()
      The selected nodes as an unmodifiable list.
      Returns:
      The nodes in document order.
    • iterator

      public Iterator<XMQNode> iterator()
      Iterate over the selected nodes, from the first node, like xmqSelectionNext. The iterator cannot remove nodes.
      Specified by:
      iterator in interface Iterable<XMQNode>
      Returns:
      A new iterator.