Atomic values are instances of a simple type according to XML Schema which means, for example, character strings as "Emma Miller" or numbers as, for example, 1.0. All simple data types predefined in XML Schema are also available in XQuery. In order to be able to easily address them, XQuery assumes that the xs prefix is bound to the XML Schema namespace "http://www.w3.org/2001/XMLSchema". Atomic values may also have an user-defined type in case it has been introduced to XQuery. However, values of types which were built by unification (union) or list generation (list), for example IDREFS and NMTOKENS, are no atomic values according to W3C - XML Schema Part 2: Datatypes.
When it is necessary to indicate a value of a certain type in a XQuery expression (for example as comparative value), this can be done with the help of a constructor. Such a constructor is available for each simple type which is known at the moment of the evaluation. The constructor is a function which has the same name as the type to be constructed. The respective value is passed on to the function as only argument. So, the expression
indicates a value of the xs:float data type. There are shorter notations for literals of some data types which will be introduced in the following:
Literals for character strings
Character strings which are enclosed in single or double quotation marks are considered as values of xs:string type, for example:
'This is a literal of xs:string type.'
"Such literals are enclosed in "" or '."
As you can see in the last example, the quotation marks which enclose the literal can also be used in the literal itself if they are duplicated.
Literals for numbers
Numbers become the type xs:integer, xs:decimal or xs:double, depending on whether they contain a decimal point and, where applicable, an exponent:
123 data type assignment: xs:integer
123.12 data type assignment: xs:decimal
.123 data type assignment: xs:decimal
1E1 data type assignment: xs:double
There are no literals for the values +INF, -INF and NaN; they have to be generated with constructors, for example, by:
Source: "XQuery – Grundlagen und fortgeschrittene Methoden", dpunkt-Verlag, Heidelberg (2004)
|<< back||next >>|