This interface represents a sequence of items as defined in the
XDM. The sequence may be materialized or non-materialized.
The next
method is useful to position the
XQSequence
over the next item in the sequence.
If the scrollability is XQConstants.SCROLLTYPE_SCROLLABLE
,
then the previous
method can be called to move backwards.
In the case of a forward only sequence, the get methods may be only called
once per item. To perform multiple gets on an item, extract the item first
from the sequence using the getItem
method and
then operate on the XQItem
object.
XQPreparedExpression expr = conn.prepareExpression("for $i ..");
XQSequence result = expr.executeQuery();
// create the ItemTypes for string and integer
XQItemType strType = conn.createAtomicType(XQItemType.XQBASETYPE_STRING);
XQItemType intType = conn.createAtomicType(XQItemType.XQBASETYPE_INT);
// positioned before the first item
while (result.next())
{
XQItemType type = result.getItemType();
// If string, then get the string value out
if (type.equals(strType))
String str = result.getAtomicValue();
else if (type.equals(intType)) // if it is an integer..
int intval = result.getInt();
...
}
In a sequence, the cursor may be positioned on an item, after the last item
or before the first item. The
getPosition
method
returns the current position number. A value of 0 indicates
that it is positioned before the first item, a value of
count() + 1
indicates that it is positioned after the last item, and any other value
indicates that it is positioned on the item at that position.
For example, a position value of 1 indicates that it is positioned on
the item at position 1.
The isOnItem
method may be used to find out if the cursor
is positioned on the item. When the cursor is positioned on an item,
the next
method call will move the cursor to be on the next item.
See also: Section 12 Serialization, XQuery API for Java
(XQJ) 1.0, which describes some general information applicable
to various XQJ serialization methods.