Types, Nodes, and Atomic Values

Element and attribute nodes, as well as atomic values, all have types associated with them. Sequences don't technically have types, although they can be matched to sequence types, as described later in this chapter.

Nodes and Types

All element and attribute nodes have type annotations, which indicate the type of their content. An element or attribute can come to be annotated with a specific type when it is validated against a schema. This might occur when the document is first opened, or as the result of a validate expression. Schema validation is discussed further in Chapter 13.

If an element or attribute has not been validated and does not have a specific type, it is automatically assigned a generic type, namely xs:untyped (for elements) or xs:untypedAtomic (for attributes). Sometimes these nodes are referred to as untyped, despite the fact that they do have a type, albeit a generic one.

Attributes, and most elements, also have a typed value.[*] This typed value is an atomic value extracted from the node, taking into account the node's type annotation. For example, if the number element has been validated and given the type xs:integer, its typed value is 784 (type xs:integer). If the number element is untyped, its typed value is 784 (type xs:untypedAtomic). The data function allows you to retrieve the typed value of a node.

Atomic Values and Types

Every atomic value has a type. An atomic value might have a specific type because:

  • It is extracted from an ...

Get XQuery now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.