• +49-(0)721-402485-12
Your experts for XML, XQuery and XML Databases

Special types in XQuery

As already mentioned, information from XML Schema or the DTD are used in order to assign atomic values which appear in a XML document to the correct type. But what happens if there is no DTD or XML Schema for a document? In this case, only an unspecific type can be assumed.

For attribute values whose types are unknown XQuery introduces the data type xdt:untypedAtomic. The xdt prefix is bound to a special XQuery namespace (like all XQuery namespaces it changes with each output of the Standard since it contains the date of the Standard, for example "http://www.w3.org/2003/11/xpath-datatypes").

The xdt:untypedAny type is assigned to element nodes with unknown type. Atomic values of unknown type get the xdt:untypedAtomic type. With the introduction of these types XQuery persues the goal of a "natural" treatment of data from untyped documents for arithmetic operations or comparisons. For this purpose, there are special rules which specify a "reasonable" type conversion of these undetermined types to "suitable" types for the respective operation.

XQuery also introduces the abstract type xdt:anyAtomicType which is derived from xs:anySimpleType. From this type in turn xdt:untypedAtomic and all the other simple types (as for example xs:integer and xs:string) are derived. This type is in particular helpful for the declaration of functions.

By analogy with SQL:1992, XQuery also introduces two subtypes of xs:duration which are (in contrast to xs:duration) completely ordered, namely xdt:yearMonthDuration (durations which are only indicated in years and months) and xdt:dayTimeDuration (durations which are only indicated in days, hours, minutes and seconds). It is possible to transform values of xs:duration type into these types. When transforming, the portions of the duration are omitted which are not designated in the appropriate type. For example,


results in the same value as


The following image (according to the W3C) shows the classification of XQuery data types into the type hierarchy as adopted by XML Schema. Ovals represent abstract types, rectangles represent concret types. The types introduced by XQuery have a grey background. The values of complex types and the values of list and union types are no values of the XQuery data model.

XQuery data types in the type hierarchy of XML Schema

Image: XQuery data types in the type hierarchy of XML Schema


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

<< backnext >>