• +49-(0)721-402485-12
Ihre Experten für XML, XQuery und XML-Datenbanken

Sequence types and node access functions

In XQuery there are some constructs where it is necessary to indicate each expected type. For example, for a function definition the types of the input parameters and of the return value must be defined. For this purpose, XQuery provides a syntax which offers a wide range of loose up to very strict type definition. Since the sequence is the essential data type of XQuery, these type definitions are called "sequence types".

Sequence type definitions

For sequence types it can be indicated on the one hand of which types the sequence may consists, on the other hand frequency conditions can be specified.

Frequency indications

The syntax for these frequency indications is borrowed from the XML DTD. The following table gives an overview of the four options to indicate the frequency.

SymbolMeaning
(none) sequence with exactly one item
?sequence with at most one item
+sequence with at least one item
*sequence with an unlimited number of items

Table: Frequency indications for sequence type definitions

As special frequency indication, also empty() is available which indicates the empty sequence. For the regular expressions from XQuery and XML Schema there are more precisely frequency indications (minimum and maximum number) which, however, are not used in other parts of XQuery.

Item types

Atomic types or node types can be used as item types. The most general item type item() allows atomic values as well as nodes. Therefore,

item()*

is the most general sequence type. All sequences, also empty sequences, match this type.

As atomic types all in XML Schema defined simple types but also all known user-defined simple types can be used, as for example:

xs:integer+
myNamespace:myShoeSize?

It should be noted here that XQuery accepts for such a definition not only the indicated type, but also each typed derived thereof by means of extension or restriction. So, if the type

xs:string

is given as sequence type, also the type RoomNumber_T is accepted, because it is derived from xs:token and this type in turn is derived from xs:string.

 

Source: "XQuery – Grundlagen und fortgeschrittene Methoden", dpunkt-Verlag, Heidelberg (2004)

<< backnext >>