Sequences and items

The XPath data model is based on the notion of a sequence. The value of an XPath expression is always 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 of the following values can each be represented as a single sequence:
  • 36
  • <dog/>
  • (2, 3, 4)
  • (36, <dog/>, "cat")
  • ()
  • An XML document

A node can occur in more than one sequence, and a sequence can contain duplicate items. A sequence cannot be a member of another sequence. In other words, 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 single item that appears on its own is modeled as a sequence that contains one item. For example, there is no distinction between the sequence (2) and the atomic value 2.

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