Sequences and items

An instance of the XQuery and XPath data model (XDM) is a sequence. A sequence is an ordered collection of zero or more items. An item is either an atomic value or a node.

A sequence can contain nodes, atomic values, or any mixture of nodes and atomic values. For example, each entry in the following list is a sequence:

  • 36
  • <dog/>
  • (2, 3, 4)
  • (36, <dog/>, "cat")
  • ()

In addition the entries in the list, an XML document stored in an XML column in a Db2 database is a sequence.

The examples use a notation to represent sequences that is consistent with the syntax that is used to construct sequences in XQuery:

  • Each item in the sequence is separated by a comma.
  • An entire sequence is enclosed in parentheses.
  • A pair of empty parentheses represents an empty sequence.
  • A single item that appears on its own is equivalent to a sequence that contains one item.

    For example, there is no distinction between the sequence (36) and the atomic value 36.

Sequences cannot be nested. When two sequences are combined, the result is always a flattened sequence of nodes and atomic values. For example, appending the sequence (2, 3) to the sequence (3, 5, 6) results in the single sequence (3, 5, 6, 2, 3). Combining these sequences does not produce the sequence (3, 5, 6, (2, 3)) because nested sequences never occur.

A sequence that contains zero items is called an empty sequence. Empty sequences can be used to represent missing or unknown information.