View Old View New View Both View Only Previous Next

This draft contains only sections that have differences from the version that it modified.

W3C

XQuery and XPath Data Model 4.0

W3C Editor's Draft 23 February 2026

This version:
https://www.w3.org/TR/2000/REC-xpath-datamodel-40-20000101/
Latest version of XQuery and XPath Data Model 4.0:
https://www.w3.org/TR/xpath-datamodel-40/
Previous versions of XQuery and XPath Data Model 4.0:
https://www.w3.org/TR/2017/PR-xpath-datamodel-31-20170117/
https://www.w3.org/TR/2016/CR-xpath-datamodel-31-20161213/
https://www.w3.org/TR/2014/CR-xpath-datamodel-31-20141218/
Most recent version of XQuery and XPath Data Model 4:
https://www.w3.org/TR/xpath-datamodel-4/
Most recent version of XQuery and XPath Data Model:
https://www.w3.org/TR/xpath-datamodel/
Most recent Recommendation of XQuery and XPath Data Model:
https://www.w3.org/TR/2014/REC-xpath-datamodel-30-20140408/
Editor:
Michael Kay, Saxonica <http://www.saxonica.com/>

This document is also available in these non-normative formats: XML.


Abstract

This document defines the data model of [XPath 4.0], [XSL Transformations (XSLT) Version 4.0], and [XQuery 4.0: An XML Query Language], and any other specifications that reference it.

Status of this Document

This section describes the status of this document at the time of its publication. Other documents may supersede this document.

This document is a working draft developed and maintained by a W3C Community Group, the XQuery and XSLT Extensions Community Group unofficially known as QT4CG (where "QT" denotes Query and Transformation). This draft is work in progress and should not be considered either stable or complete. Standard W3C copyright and patent conditions apply.

The community group welcomes comments on the specification. Comments are best submitted as issues on the group's GitHub repository.

The community group maintains two extensive test suites, one oriented to XQuery and XPath, the other to XSLT. These can be found at qt4tests and xslt40-test respectively. New tests, or suggestions for correcting existing tests, are welcome. The test suites include extensive metadata describing the conditions for applicability of each test case as well as the expected results. They do not include any test drivers for executing the tests: each implementation is expected to provide its own test driver.

Dedication

The publications of this community group are dedicated to our co-chair, Michael Sperberg-McQueen (1954–2024).


4 Schemas and Types

4.2 Type System

Every value manipulated by XPath, XQuery, or XSLT is a sequence comprising zero or more items.

[Definition: A sequence type constrains the set of permitted sequences, by defining the permitted item types and the permitted number of items in the sequence (exactly zero, exactly one, zero-or-more, one-or-more, zero-or-one).]

Every item is an instance of one or more item types:

  • All items are instances of the type item(). There are three kinds of item: atomic items, generic nodes (GNodes), and function items.

  • Every atomic item is an instance of a specific atomic type determined by its type annotation; it is also an instance of every type from which that type is derived by restriction (directly or indirectly), and of every union type that includes that type as a member type.

  • A generic node (GNode) is either an XNode (for "XML node"), or a JNode (for "JSON node"). For continuity reasons, throughout these specifications the term node, when used without qualification, means an XNode; furthermore the item type node() refers exclusively to an XNode. The term XNode is used only when there is a need to distinguish clearly from JNodes.

    XNodes represent the constructs found in an XML document. Every node (that is, every XNode) is an instance of the type node(), and more specifically it is an instance of one of seven node kinds: document(), element(*), attribute(*), text(), comment(), processing-instruction(), or namespace(). Nodes may also be instances of more specific types characterized by the node name and type annotation.

    JNodes are newly introduced in 4.0 for the purpose of navigating trees of maps and arrays, typically derived by parsing JSON. A JNode wraps a value (which may be any sequence).

  • Every function item is an instance of the generic type function(*), and also of a specific function type defining the types of the function's parameters and the type of the result.

    A map item, as well as being a function, is also an instance of the generic map type map(*), of more specific map types map(K, V) defining the types of the keys and values, and perhaps of one or more record types that associate a type with specific key values.

    An array item, as well as being a function, is also an instance of the generic array type array(*), and also of more specific array types array(M) defining the type of the array's members.

This section describes how item types relate to each other.

The diagrams below show how nodes, functions, primitive simple types, and user defined types fit together into a type system. In the diagrams, connecting lines represent relationships between derived types and the types from which they are derived; the latter are always higher and to the left of the latter.

The xs:IDREFS, xs:NMTOKENS, xs:ENTITIES types, and xs:numeric, and both the user-defined list types and user-defined union types are special types in that these types are lists or unions rather than types derived by extension or restriction.

The first diagram illustrates the relationship of various item types. Item types in the data model form a directed graph, rather than a hierarchy or lattice: in the relationship defined by the derived-from(A, B) function, some types are derived from more than one other type. Examples include functions (function(xs:string) as xs:int is substitutable for function(xs:NCName) as xs:int and also for function(xs:string) as xs:decimal), and union types (A is substitutable for the union type (A | B) and also for the union type (A | C)). In XDM, item types include node types, function types, and built-in atomic types. The list, which shows only hierarchic relationships, is therefore a simplification of the full model.

  • item (abstract)

    • anyAtomicType (built-in atomic)

    • GNode (node)

      • XNode (node)

        • attribute (node)

          • user-defined attribute types (user-defined)

        • document (node)

          • user-defined document types (user-defined)

        • element (node)

          • user-defined element types (user-defined)

        • text (node)

        • comment (node)

        • processing-instruction (node)

        • namespace (node)

      • JNode (node)

    • function (function item)

      • user-defined function item types (user-defined)

      • array (function item)

        • user-defined array types (user-defined)

      • map (function item)

        • user-defined map types (user-defined)

        • user-defined record types (user-defined)

Legend:

  • Supertype

    • subtype

  • Abstract types (abstract)

  • Built-in atomic types (built-in atomic)

  • Node types (node)

  • Function item types (function item)

  • User-defined types (user-defined)

The XPath Data Model is the abstraction over which XPath expressions are evaluated. Historically, all of the items in the data model could be derived directly (nodes) or indirectly (typed values, sequences) from an XML document. However, as the XPath expression language has matured, new features have been added which require additional types of items to appear in the data model. These items have no direct XML serialization, but they are never the lessnevertheless part of the data model.

The next diagram shows all of the atomic types, including the primitive simple types and the built-in types derived from the primitive simple types. This includes all the built-in datatypes defined in [Schema Part 2]. Atomic types act both as item types (meaning they can be used to declare the types of variables and function arguments), and as schema types (meaning they can be used as type annotations on nodes).

  • anyAtomicType

    • anyURI

    • base64Binary

    • boolean

    • date

    • dateTime

      • dateTimeStamp

    • decimal

      • integer

        • long

          • int

            • short

              • byte

        • nonNegativeInteger

          • positiveInteger

          • unsignedLong

            • unsignedInt

              • unsignedShort

                • unsignedByte

        • nonPositiveInteger

          • negativeInteger

    • double

    • duration

      • dayTimeDuration

      • yearMonthDuration

    • float

    • gDay

    • gMonth

    • gMonthDay

    • gYear

    • gYearMonth

    • hexBinary

    • NOTATION

    • QName

    • string

      • normalizedString

        • token

          • NMTOKEN

          • Name

            • NCName

              • ENTITY

              • ID

              • IDREF

          • language

    • time

    • untypedAtomic

Legend:

  • Supertype

    • subtype

  • Built-in atomic types

For further detail regarding atomic items see 5 Atomic Items.