Literal value expressions
This page contains examples of some simple literal values in XQuery. Each example below is a complete and valid XQuery expression.
An xs:integer is just as you’d expect:
5
A double-precision floating point xs:double:
123.4E-5
A fixed point, arbitrary precision xs:decimal:
123.4
It’s important to note the distinction here between what you get with and without the scientific exponential notation. The first example returns an xs:double and would map most naturally to java.lang.Double in Java. The second example returns an xs:decimal and would map to java.math.BigDecimal in Java. The XQuery specification actually allows some wiggle room for implementers in what precision is supported by a literal decimal. This is done to allow implementations to use a limited (but still fixed) precision to allow more efficient operation. Most implementations take advantage of this freedom, so this is an area where engines may present incompatible behavior.
Strings can be created with either a single-tick string or a double-quoted string. In each case, the quote character can be used to escape that kind of quote. Some examples:
“abc”
‘abc’
“He said “”Whoa”".”
‘I can'’t hear you!’
Literal booleans can be created with some special functions:
false()
true()
Any type can be constructed using it’s string form (even user-defined types specified in schemas):
xs:dateTime(”2006-12-31T23:59:59.123″)
