This document is also available in these non-normative formats: XML.
Copyright © 2002 W3C® (MIT, INRIA, Keio), All Rights Reserved. W3C liability, trademark, document use, and software licensing rules apply.
This document defines the W3C XQuery 1.0 and XPath 2.0 Data Model, which is the data model of at least [XSLT 2.0], and [XQuery 1.0: A Query Language for XML], and any other specifications that reference it. This data model is based on the data models of [XPath] and [XML Query Data Model] and replaces [XML Query Data Model]. This document is the result of joint work by the [XSL Working Group] and the [XML Query Working Group].
This section describes the status of this document at the time of its publication. Other documents may supersede this document. The latest status of this document series is maintained at the W3C.
This is a Public Working Draft for review by W3C Members and other interested parties. It is a draft document and may be updated, replaced or made obsolete by other documents at any time. It is inappropriate to use W3C Working Drafts as reference material or to cite them as other than "work in progress". This is work in progress and does not imply endorsement by the W3C membership.
The XQuery 1.0 and XPath 2.0 Data Model has been defined jointly by the XML Query Working Group (part of the XML Activity) and the XSL Working Group (part of the Style Activity).
Comments on this document should be sent to the W3C mailing list public-qt-comments@w3.org. (archived at http://lists.w3.org/Archives/Public/public-qt-comments/).
A list of current W3C Recommendations and other technical documents can be found at http://www.w3.org/TR/.
Patent disclosures relevant to this specification may be found on the XML Query Working Group's patent disclosure page at http://www.w3.org/2002/08/xmlquery-IPR-statements and the XSL Working Group's patent disclosure page at http://www.w3.org/Style/XSL/Disclosures.html.
1 Introduction
2 Notation and Pseudo-code Syntax
3 Concepts
3.1 Node Identity
3.2 Document Order
3.3 XML Schemas and the XML Information Set
3.4 Types
3.5 Typed Value and String Value
3.6 Mapping PSV Infoset additions to Types
3.7 Comments, Processing Instructions, and Whitespace
4 Nodes
4.1 Accessors
4.1.1 base-uri Accessor
4.1.2 node-kind Accessor
4.1.3 node-name Accessor
4.1.4 parent Accessor
4.1.5 string-value Accessor
4.1.6 typed-value Accessor
4.1.7 type Accessor
4.1.8 children Accessor
4.1.9 attributes Accessor
4.1.10 namespaces Accessor
4.2 Documents
4.2.1 Overview
4.2.2 Constructor
4.2.3 Accessors
4.2.4 PSVI to Datamodel Mapping
4.2.5 Data Model to Infoset Mapping
4.3 Elements
4.3.1 Overview
4.3.2 Constructor
4.3.3 Accessors
4.3.4 PSVI to Data Model Mapping
4.3.5 Data Model to Infoset Mapping
4.4 Attributes
4.4.1 Overview
4.4.2 Constructor
4.4.3 Accessors
4.4.4 PSVI to Data Model Mapping
4.4.5 Data Model to Infoset Mapping
4.5 Namespaces
4.5.1 Overview
4.5.2 Constructor
4.5.3 Accessors
4.5.4 PSVI to Data Model Mapping
4.5.5 Data Model to Infoset Mapping
4.6 Processing Instructions
4.6.1 Overview
4.6.2 Constructor
4.6.3 Accessors
4.6.4 PSVI to Data Model Mapping
4.6.5 Data Model to Infoset Mapping
4.7 Comments
4.7.1 Overview
4.7.2 Constructor
4.7.3 Accessors
4.7.4 PSVI to Data Model Mapping
4.7.5 Data Model to Infoset Mapping
4.8 Text
4.8.1 Overview
4.8.2 Constructor
4.8.3 Accessors
4.8.4 PSVI to Data Model Mapping
4.8.5 Data Model to Infoset Mapping
5 Atomic Values
6 Sequences
A XML Information Set Conformance
B References
C References (Non-Normative)
D Example (Non-Normative)
E Open Issues (Non-Normative)
F Recently Closed Issues (Non-normative)
This document defines the XQuery 1.0 and XPath 2.0 Data Model, which is the data model of [XPath 2.0], [XSLT 2.0] and [XQuery 1.0: A Query Language for XML]
The XQuery 1.0 and XPath 2.0 Data Model (henceforth "data model") serves two purposes. First, it defines precisely the information contained in the input to an XSLT or XQuery processor. Second, it defines all permissible values of expressions in the XSLT, XQuery, and XPath languages. A language is closed with respect to a data model if the value of every expression in a language is guaranteed to be in the data model. XSLT 2.0, XQuery 1.0, and XPath 2.0 are all closed with respect to the data model.
The data model is based on the [XML Information Set] (henceforth "Infoset"), but it requires the following new features to meet the [XPath Requirements Version 2.0] and [XML Query Requirements]:
Support for XML Schema types. The XML Schema recommendations define features, such as structures ([XMLSchema Part 1]) and simple data types ([XMLSchema Part 2]), that extend the XML Information Set with precise type information.
Representation of collections of documents and of complex values. ([XML Query Requirements])
As with the Infoset, the XQuery 1.0 and XPath 2.0 Data Model specifies what information in the documents is accessible, but it does not specify the programming-language interfaces or bindings used to represent or access the data.
Every value handled by the data model is a sequence of zero or more items. An item is either a node or an atomic value. A node is defined in 4 Nodes and is one of seven node kinds. An atomic value encapsulates an XML Schema atomic type and a corresponding value of that type. They are defined in 5 Atomic Values. A sequence is an ordered collection of nodes, atomic values, or any mixture of nodes and atomic values. A sequence cannot be a member of a sequence. A single item appearing on its own is modeled as a sequence containing one item. Sequences are defined in 6 Sequences.
Note:
In XPath 1.0, the data model only defines nodes. The primitive data types (number, boolean, string, node-set) are part of the expression language, not the data model.
The data model can represent various values including not only the input and the output of a stylesheet or query, but all values of expressions used during the intermediate calculations. Examples include the input document or document repository (represented as a document node or a sequence of document nodes), the result of a path expression (represented as a sequence of nodes), the result of an arithmetic or a logical expression (represented as an atomic value), a sequence expression resulting in a sequence of items, etc. Examples of values that cannot be expressed directly by the data model include schema components and atomic values whose type is not an XML Schema atomic type.
In this document, we provide a precise definition of how values in the XQuery 1.0 and XPath 2.0 Data Model are constructed and accessed, and how they relate to values in the Infoset. We note wherever the XQuery 1.0 and XPath 2.0 Data Model differs from that of XPath 1.0.
In addition to prose, we define two sets of functions to explain the data model: accessors and constructors. The accessors and constructors defined by the data model are shown with the prefix dm. The prefix is always shown in italics to emphasize that these functions are abstract; they exist to explain the interface between the data model and specfications that rely on the data model: they are not and cannot be made accessible directly from the host language.
The signature of accessors and constructors is shown using the same style as [XQuery 1.0 and XPath 2.0 Functions and Operators]. For example:
In the psuedo-code syntax, the term Node denotes the category of node values, AtomicValue denotes the category of atomic values, and Item refers to the category of either node values or atomic values.
Some accessors and constructors can accept or return sequences. The following notation is used to denote sequence values:
V* denotes a sequence of zero or more items of type V.
V? denotes a sequence of exactly zero or one items of type V.
V+ denotes a sequence of one or more items of type V.
In a sequence, V may be a Node or AtomicValue, or the union (choice) of several categories of Items.
There are some functions in the data model that are partial functions. We use the occurrence indicators ? or * when specifying the return type of such functions. For example, a node may have one parent node or no parent. If the node argument has a parent, the dm:parent accessor returns a singleton sequence. If the node argument does not have a parent, it returns the empty sequence. The signature of dm:parent specifies that it returns an empty sequence or a sequence containing one node:
Note:
The XPath 1.0 data model defines accessors, but does not define constructors.
This document relies on the [XML Information Set]. Information items and properties are indicated by the styles information item and [property], respectively.
This document frequently uses the term expanded-QName. [Definition: An expanded-QName is a pair of values consisting of a namespace URI and a local name. They belong to the value space of the XML Schema type xs:QName. When this document refers to xs:QName we always mean the value space, i.e. a namespace URI, local name pair (and not the lexical space referring to constructs of the form prefix:local-name).]
Because XML documents are tree-structured, we define the data model using conventional terminology for trees. The data model is a node-labeled, tree-shaped graph, but also includes a concept of node identity. The identity of a node is established when a node-constructor is applied to create the node: each application of a node constructor creates a new node that is identical to itself, and not identical to any other node (see 4 Nodes).
This concept should not be confused with the concept of a unique ID, which is a unique name assigned to an element by the author to represent references using ID/IDREF correlation.
[Definition: A document order is defined on all the nodes in a document. Document order is a total ordering, although the relative order of some nodes is implementation-dependent. Informally, document order is the order returned by an in-order, depth-first, left-to-right traversal of the data model.] There is precisely one document order and it satisfies the following constraints.
The document node is the first node.
The relative order of siblings is determined by their order in the XML representation. A node N1 occurs before a node N2 in document order if and only if the start of N1 occurs before the start of N2 in the XML document.
Element nodes occur before their children; children occur before following-siblings.
Namespace nodes immediately follow the element node with which they are associated. The relative order of namespace nodes is stable but implementation-dependent.
Attribute nodes immediately follow the namespace nodes of the element with which they are associated. The relative order of attribute nodes is stable but implementation-dependent.
Reverse document order is the reverse of document order.
The relative order of nodes in distinct documents is implementation-dependent but stable. In other words, given two distinct documents A and B, if a node in document A is before a node in document B, then every node in document A is before every node in document B.
Note:
The relative order of free-floating nodes (those not in a document) is not defined. See [Issue-0050: Relative order of free-floating nodes].
The data model is defined in terms of the [XML Information Set] after XML Schema validity assessment. XML Schema validity assessment is the process of assessing an XML element information item with respect to an XML Schema and augmenting it and some or all of its descendants with properties that provide information about validity and type assignment. [Definition: The result of schema validity assessment is an augmented Infoset, known as the Post Schema-Validation Infoset, or PSVI.]
The data model supports well-formed XML documents conforming to [Namespaces in XML]. XML documents that are not well-formed are not XML, by definition. XML documents that do not conform to [Namespaces in XML] are not supported (they are not supported by [XML Information Set]).
In other words, the data model supports the following classes of XML documents:
Well-formed documents conforming to [Namespaces in XML],
DTD-valid documents conforming to [Namespaces in XML], and
W3C XML Schema-validated documents.
The data model supports some kinds of values that are not supported by [XML Information Set]. Examples of these are well-formed document fragments, sequences of fragments or sequences of documents. The data model also supports values that are not nodes. Examples of these are atomic values, sequences of atomic values, or sequences mixing nodes and atomic values. These are necessary to be able to represent the results of intermediate expressions in the data model during expression processing.
Schema-validated documents include documents in which some elements or attributes have been validated by "lax" or "skip" validation ([XMLSchema Part 2]).
An "incompletely validated document" is an XML document that has a corresponding schema but whose schema-validity assessment has resulted in one or more element or attribute information items being assigned values other than 'valid' for the [validity] property in the PSVI.
The data model supports incompletely validated documents.
Note:
This implies accommodation for the case where both a DTD and a schema are applied. This will probably require some reconciliation of the [attribute type] property with type information from the PSVI. See issues [Issue-0004: Schema/DTD], [Issue-0081: Schema-less documents with a DTD].
In addition to specifying the transformation from the Post Schema Validation Infoset (PSVI) to the data model, this document also specifies the transformation from the data model back to the XML Information Set. This is a useful notion that can be used for defining serialization and validation. Serialization can be viewed as a two step process, first transforming to the XML Infoset and then to an XML document. Validation is described conceptually as a process of mapping the data model to the XML Infoset followed by XML Schema validation producing a PSVI which is then loaded into the data model.
See [Issue-0085: Globally declared namespaces in the infoset].
The data model supports a representation of named types as
expanded-QNames.
Named types include both the built-in types defined by
[XMLSchema Part 2] and user-types declared in a schema
and imported by a stylesheet or query.
Since named types in XML Schema are global, an expanded-QName
uniquely identifies such a type.
The namespace name of the expanded-QName is the target namespace
of the schema and its local name is the name of the type.
The data model does not uniquely identify anonymous types and
represents them by xs:anyType or xs:anySimpleType.
The data model associates type information with element nodes,
attribute nodes and atomic values. If this type information is
something other than xs:anyType or
xs:anySimpleType, the item is guaranteed to be a valid
instance of that type as defined by XML Schema.
The data model defines an accessor dm:type that returns
an expanded-QName corresponding to the type of the element node,
attribute node or atomic value.
It returns xs:anyType or xs:anySimpleType if it is
locally declared, if no type information exists, or if it failed W3C XML Schema
validity assessment.
When no type information exists for an element or an attribute node we frequently use the terminology "element with unknown type" or "attribute with unknown simple type".
The data model does not represent element or attribute declaration schema components, but it supports various type-related operations. The semantics of such operations, e.g. checking if a particular instance of an element node has a given type is defined in [XQuery 1.0 Formal Semantics].
The content of a text, attribute, or element node can be interpreted in two ways: as a string value or as a typed value. For these types of nodes, the typed value can be extracted by the dm:typed-value accessor, and the string value can be extracted by the dm:string-value accessor.
The string value of a node is a single xs:string
derived from the content of the node as described in the definitions
of the accessor functions for each kind of node.
The typed value of a node is a sequence of atomic values derived from its string value and its type in a way that is consistent with schema validation, as described in the definitions of the accessor functions for each kind of node.
This section specifies how the type of an element or attribute node is computed from the PSVI properties that specify validity and type assessment for the node's corresponding information item.
See [Issue-0077: PSVI to Type mapping dependence on conformance levels].
A PSVI element or attribute information item has a [validity] property. The [validity] property may be "valid", "invalid", or "notKnown" and reflects the outcome of schema-validity assessment. The only information that can be inferred from an invalid or not known validity value is that the information item is well-formed, therefore, we must associate some general type information with the element or attribute node if it is not known to be valid.
The precise definition of the type of an element or attribute information item depends on the properties of the PSVI. XML Schema only guarantees the existence of either the [type definition] property, or the [type definition namespace], [type definition name] and [type definition anonymous] properties. If the type definition refers to a union type, there are further properties defined, that refer to the type definition which actually validated the item's normalized value. These properties are either the [member type definition], or the [member type definition namespace], [member type definition name] and [member type definition anonymous] properties. If these are available, the type of an element or attribute will refer to the member type that actually validated the schema normalized value.
The type of an element information item is represented by an expanded-QName whose namespace and local name correspond to the first applicable items in the following list:
If the [validity] property exists and is ""valid":
If [member type definition] exists and its {name} property is present:
The {target namespace} and {name} properties of the [member type definition] property.
If the [type definition] property exists and its {name} property is present:
The {target namespace} and {name} properties of the [type definition] property.
If [member type definition anonymous] exists and is false: the [member type definition namespace] and the [member type definition name].
If [type definition anonymous] exists and is false: the [type definition namespace] and the [type definition name]
Otherwise, xs:anyType for elements or
xs:anySimpleType for attributes.
| Editorial note | |
| The above definition is currently under discussion. It is very likely that a change will be made in a future draft to reflect a more precise definition covering derived types and the possible usage of generated type identifiers when no type names available. See [Issue-0076: PSVI to Type mapping supporting derived types]. | |
Although the data model is able to represent comments, processing instructions, and insignificant whitespace, preservation of this information may be unnecessary and onerous for some applications.
An instance of the data model can be constructed from an Infoset, a PSVI, or from some other data source entirely. Different applications may or may not choose to construct nodes in the data model to represent comments, processing instructions, and insignificant white space. These decisions are considered outside the scope of the data model. Consequently the data model makes no attempt to control or identify the sort of processing in this regard that an application uses to construct a data model instance.
The category of Node values contains seven distinct kinds of nodes: document, element, attribute, text, namespace, processing instruction, and comment. The seven kinds of nodes are defined in the following subsections.
Each kind of node has its own constructor. The effect of a node constructor is to create a new node with a unique identity, distinct from all other nodes.
A tree contains a root plus all nodes that are reachable directly or indirectly from the root via the dm:children, dm:attributes, and dm:namespace accessors. Every node belongs to exactly one tree, and every tree has exactly one root node. A tree whose root node is a document node is referred to as a document. A tree whose root node is some other kind of node is referred to as a fragment.
A set of accessors is defined on all seven kinds of Nodes. Some accessors return a constant empty sequence on certain node kinds.
See [Issue-0091: Support for substitution groups].
In order for applications to be able to operate on instances of the data model, the model must expose properties of the items it contains. The data model does this by defining a family of accessor functions. These are not functions in the literal sense, they are not available for users or applications to call directly, rather they are descriptions of the interface that an implementation of the data model must expose to applications. Functions and operators available to end-users are described in [XQuery 1.0 and XPath 2.0 Functions and Operators].
The following table summarizes the accessor functions and the types of values that they return if called on a node of each type.
| Document Node | Element Node | Attribute Node | Namespace Node | P.I. Node | Comment Node | Text Node | |
| dm:base-uri | xs:anyURI? | ||||||
| dm:node-kind | xs:string | ||||||
| dm:node-name | () | xs:QName | xs:QName | xs:QName? | () | () | () |
| dm:parent | () | Node? | Node? | Node? | Node? | Node? | Node? |
| dm:string-value | xs:string | ||||||
| dm:typed-value | () | Value? | Value? | () | () | () | Value? |
| dm:type | () | xs:QName? | xs:QName? | () | () | () | () |
| dm:children | Node+ | Node* | () | () | () | () | () |
| dm:attributes | () | Node* | () | () | () | () | () |
| dm:namespaces | () | Node* | () | () | () | () | () |
The dm:base-uri accessor returns a sequence containing zero or one uri references.
Document, element, and processing-instruction nodes have a base-uri property. If that property is non-empty, its value is returned.
If the accessor is called on a node that does not have a base-uri property, or whose base-uri property is empty, the base-uri of that node's parent is returned. If the node has no parent, an error is raised. See [Issue-0087: base-uri should return ()?]
node-kind AccessorThe dm:node-kind accessor returns a string value identifying the kind of node on which the accessor was called. One of the following values is returned:
"document" for document nodes.
"element" for element nodes.
"attribute" for attribute nodes.
"text" for text nodes.
"namespace" for namespace nodes.
"processing-instruction" for processing instruction nodes.
"comment" for comment nodes.
node-name AccessorThe dm:node-name accessor returns a sequence of zero or one xs:QNames.
For element and attribute nodes, dm:node-name returns the qualified name of the element or attribute.
For processing-instructions nodes, dm:node-name returns an xs:QName with a the processing instruction target name in the local-name and no namespace URI.
For namespace nodes, dm:node-name returns an xs:QName with the prefix of the namespace declaration in the local-name and no namespace URI. If the namespace declaration declares the default namespace, which has no prefix, an empty sequence is returned.
Some implementations may not preserve information about the prefixes declared. In these cases, the dm:node-name accessor returns the empty sequence when applied to processing-instruction nodes.
parent AccessorThe dm:parent accessor returns a sequence containing zero or one nodes.
For nodes that have a parent, dm:parent returns the parent node. For all other nodes, it returns the empty sequence.
If the return value is not the empty sequence, it will always be either an element node or a document node.
string-value AccessorThe dm:string-value accessor returns a string representation of the node.
For some kinds of nodes, this is part of the node; for other kinds of nodes, it is computed from the dm:string-value of its descendant nodes.
The dm:string-value accessor can be used to recover the
lexical representation of an atomic value. The details of converting
an atomic value to its string representation are described in the
"Casting Functions" section of [XQuery 1.0 and XPath 2.0 Functions and Operators].
In particular if the atomic value's type is primitive,
dm:string-value returns the atomic value's canonical
lexical representation for that primitive type as specified in
[XMLSchema Part 2]. If the atomic value's type is derived, the
lexical representation depends on whether a value is supplied for the
type's pattern facet: If no such value is supplied
dm:string-value returns the atomic value's canonical
lexical representation for the primitive base type.
Otherwise dm:string-value returns a lexical
representation that matches the value specified for the pattern facet.
(This case includes xs:integers.) See [Issue-0072: Lexical representation of Schema primitive types].
Note:
Using the canonical lexical representation for atomic values as described above may not always be compatible with XPath 1.0.
typed-value AccessorThe dm:typed-value accessor returns the typed-value
of the node, which is a sequence of zero or more atomic values.
The typed-value is closely related to the node's string-value and its
type. For instance when the node's string-value is "3.14" and its type
is xs:decimal, the typed-value is a sequence containing the
atomic value 3.14 of type decimal.
In fact, when the type is an atomic type, typed-value is always the
atomic-value constructed from the string-value and the type.
In the general case, dm:typed-value constructs a sequence of atomic values. These values are derived from the string-value of the element and its type, in such a way as to be consistent with validation.
See [Issue-0080: Typed value of Document, PI and Comment nodes].
If the node (or node kind) has no typed value, the empty sequence is returned.
type AccessorThe dm:type accessor returns a sequence containing zero or one xs:QName.
For element nodes, dm:type returns the globally declared QName of the type of the node or xs:anyType if it is locally declared or no type information exists.
For attribute nodes, dm:type returns the globally declared QName of the type of the node or xs:anySimpleType if it is locally declared or no type information exists.
For other node kinds, it always returns the empty sequence.
children AccessorThe dm:children accessor returns a sequence containing zero or more nodes.
For document and element nodes, it returns the nodes that are the children of that node. It returns the empty sequence for document and element nodes that have no children.
For all other nodes, it always returns the empty sequence.
A document node or an element node is the parent of each of its child nodes. Nodes never share children: if two nodes have distinct identities, then no child of one node will be a child of the other node.
attributes AccessorThe dm:attributes accessor returns a sequence containing zero or more attribute nodes.
For element nodes, these are the attributes of the node. For all other nodes, it always returns the empty sequence.
namespaces AccessorThe dm:namespaces accessor returns a sequence containing zero or more namespace nodes.
For element nodes, these are the namespaces of the node. For all other nodes, it always returns the empty sequence.
Document nodes encapsulate XML documents. Documents have the following properties:
base-uri, possibly empty.
children
Document nodes must satisfy the following constraints.
An document node's children may not contain two consecutive text nodes. Consecutive text nodes are collapsed by the document constructor into one text node.
If a node N is a child of a document D, then the parent of N must be D.
If a node N has a parent document D, then N must be among the children of D.
Every child of a document must be distinct.
In a well-formed document, the children of the document node consist exclusively of element nodes, processing-instruction nodes, and comment nodes, and exactly one of these children is an element node. A document node in the data model is more permissive: it allows more than one element node as a child and also permits text nodes as children. See [Issue-0074: Do we need Document fragments].
Note:
Document nodes and XPath 1.0 root nodes are essentially identical.
A document node can be constructed using dm:document-node which returns a new node with unique identity, distinct from all other nodes.
The constructor takes an optional base URI value and a non-empty sequence of children nodes as arguments.
The sequence of nodes passed as $children must not be
empty and must consist only of element, processing instruction,
comment, and text nodes. See [Issue-0090: Documents can be empty].
If consecutive text nodes are specified as the children of a document node they are collapsed into one text node whose string value is the concatenation of the string values of the consecutive text nodes.
| Accessor | Returns: |
| dm:base-uri | The value of the base-uri property |
| dm:node-kind | "document" |
| dm:node-name | () |
| dm:parent | () |
| dm:string-value | The concatenation of the string-values of all the text node descendants of the document in document order |
| dm:typed-value | () |
| dm:type | () |
| dm:children | The children of the document node |
| dm:attributes | () |
| dm:namespaces | () |
Two additional accessors are defined on document nodes:
dm:unparsed-entity-system-id( | $node | as DocumentNode, |
$entityname | as xs:string) as xs:string? |
The dm:unparsed-entity-system-id accessor returns the
system identifier of an unparsed external entity declared in the
specified document. If no entity with the name specified in $entityname
exists, or if the entity is not an external unparsed entity, the empty sequence
is returned.
dm:unparsed-entity-public-id( | $node | as DocumentNode, |
$entityname | as xs:string) as xs:string? |
The dm:unparsed-entity-public-id accessor returns the
public identifier of an unparsed external entity declared in the
specified document. If no entity with the name specified in $entityname
exists, or if the entity is not an external unparsed entity, or if the entity
has no public identifier, the empty sequence
is returned.
When a data model fragment is created from the PSVI, a document information item is mapped to a Document Node. The precise transformation is described by specifying the PSVI property corresponding to each argument of the document node constructor:
| Argument | Value: |
$base-uri | The value of the [base URI] property |
$children | The sequence of nodes constructed from the information items found in the [children] property. |
To construct the value of the $children argument, for
each element, processing instruction, comment, and maximal sequence of
adjacent characater information items found in the
[children] property, a corresponding
Element, Processing Instruction, Comment, and Text node is constructed
and that sequence of nodes is used as the value. If present among the
[children], the
[document type declaration] information item
is ignored.
Note:
There is no way to determine what DTD might apply to the data model. See [Issue-0042: System Id and Public Id are not exposed].
The mapping of the data model to the XML Information Set maps a Document Node to a document information item. The properties of the document information item are constructed as follows:
| Property | Value: |
| [base URI] | The value returned by the dm:base-uri accessor |
| [children] | The sequence of information items constructed from the nodes returned by the dm:children accessor. In other words, for each node returned by the dm:children accessor, a corresponding information item is constructed and that sequence of information items is used as the value for the [children] property. |
| [notations] | The values of these properties are implementation-defined but must be consistent with the rest of InfoSet constructed. |
| [unparsed entities] | |
| [character encoding scheme] | |
| [standalone] | |
| [version] | |
| [all declarations processed] |
Note:
Since Document Nodes are more permissive than document information items, the resulting InfoSet may be invalid.
Element nodes encapsulate XML elements. Elements have the following properties:
base-uri, possibly empty.
node-name
parent
type, possibly empty
children, possibly empty
attributes, possibly empty
namespaces, possibly empty
Element nodes must satisfy the following constraints.
An element node's children may not contain two consecutive text nodes. Consecutive text nodes are collapsed by the element constructor into one text node.
If a node N is a child of an element E, then the parent of N must be E.
If a node N has a parent element E, then N must be among the children of E.
Every child of an element must be distinct.
The attributes of an element must have distinct names.
The namespace nodes of an element must have distinct names.
At most one of the namespace nodes of an element has no name (this is the
default namespace). A namespace node whose namespace URI is the zero-length
string must have no name. No namespace node may have the name "xmlns".
The element node constructor assures that the first three constraints are satisfied.
Note:
The data model does not enforce a constraint that the namespaces of an element must be a superset of the namespaces of its parent, nor does it enforce a constraint that the namespaces of an element must include namespace nodes for each of the namespace URIs used in the element name and the names of its attributes, or of namespace URIs used in the content of elements and attributes of type xs:QName. Applications of the data model (such as XSLT and XQuery) may enforce such constraints in particular circumstances, but these constraints are not part of the data model.
An element node can be constructed using dm:element-node which returns a new node with unique identity, distinct from all other nodes.
The constructor takes an expanded-QName, a sequence of namespace nodes, a sequence of attribute nodes, a sequence of child nodes, the node's type, and an optional base URI as arguments.
dm:element-node( | $qname | as xs:QName, |
$nsnodes | as NamespaceNode*, | |
$attrnodes | as AttributeNode*, | |
$children | as Node*, | |
$type | as xs:QName) as ElementNode |
dm:element-node( | $qname | as xs:QName, |
$nsnodes | as NamespaceNode*, | |
$attrnodes | as AttributeNode*, | |
$children | as Node*, | |
$type | as xs:QName, | |
$base-uri | as xs:anyURI) as ElementNode |
The sequence of nodes passed as $children
must consist only of element, processing instruction,
comment, and text nodes.
If consecutive text nodes are specified as the children of an element node they are collapsed into one text node whose string value is the concatenation of the string values of the consecutive text nodes.
To guarantee that the parent-child relationship is invertible, (i.e. that the parent of any child of a node is itself and that any node that has a parent is among its parent's children), the element constructors logically create a copy of all of their namespace, attribute, and children arguments and set the parent property of these nodes to the newly created element node. As long as the parent-child constraint is satisfied, an implementation of the data model may choose to use specialized techniques to avoid creating physical copies of the arguments to an element constructor. See [Issue-0052: Element constructor copies nodes?].
The data model permits element nodes without parents. In fact element nodes created by the element node constructor never have parents unless they are enclosed in other node constructors. Such nodes may represent partial results during expression processing.
| Accessor | Returns: |
| dm:base-uri | The base URI of the element or its parent |
| dm:node-kind | "element" |
| dm:node-name | The QName of the element |
| dm:parent | The parent element or document node |
| dm:string-value | The concatenation of the string-values of all the text node descendants of the element in document order |
| dm:typed-value | The typed value of the node |
| dm:type | Returns the QName of the element's globally declared type or the empty sequence if the element's type is locally declared or is unavailable |
| dm:children | The children of the element node |
| dm:attributes | The attributes of the element node |
| dm:namespaces | The namespaces of the element node |
The dm:base-uri accessor returns the base-uri property of the element node, if it exists. If it does not exist, the base URI of the element's parent is returned. In other words, the value returned must be the same as the value of dm:base-uri(dm:parent()) although implemetations are not required to implement it in that way.
The accessors dm:namespaces and dm:attributes return the same set of namespace and attribute nodes (respectively) that were supplied to the constructor, but they are not constrained to return them in the same order. See [Issue-0086: Nodes returned by namespaces and attributes]
The dm:parent accessor returns the empty sequence if the element has no parent.
If the element node's type is xs:anyType, the
dm:typed-value accessor returns the node's string value
as xs:anySimpleType. If the type is a complex type with complex content,
invoking dm:typed-value raises an error.
The dm:typed-value accessor returns the typed-value
of the node, which is a sequence of zero or more atomic values.
The typed-value is closely related to the node's string-value and its
type. For instance when the node's string-value is "3.14" and its type
is xs:decimal, the typed-value is a sequence containing the
atomic value 3.14 of type decimal.
In fact, when the type is an atomic type, typed-value is always the
atomic-value constructed from the string-value and the type.
In the general case, dm:typed-value constructs a sequence of atomic values. These values are derived from the string-value of the element and its type, in such a way as to be consistent with validation.
| Editorial note | |
| The dm:string-value of a node and the result of casting the dm:typed-value of a node to a string may give different results under this definition. The issue of whether to allow or possibly mandate that dm:string-value return the same result as the string-value of the typed value is still under discussion. See [Issue-0079: String-value vs. string-value of the typed-value]. | |
When a data model fragment is created from the PSVI, an element information item is mapped to an Element Node. The precise transformation is described by specifying the PSVI property corresponding to each argument of the element node constructor.
$qnameAn xs:QName constructed from the
[local name] property
and the
[namespace name] property
$nsnodesA set of Namespace Nodes constructed from the namespace information items appearing in the [in-scope namespaces] property.
Implementations may provide mechanisms to allow some or all of the namespaces in the [in-scope namespaces] property to be discarded from the data model.
$attrnodesA set of Attribute Nodes constructed from the
attribute information items
appearing in the [attributes]
property. This includes all of the "special" attributes
(xml:lang, xml:space, xsi:type, etc.)
but does not include namespace declarations (because they are not attributes).
The special nature of xsi:nil is still being discussed,
see [Issue-0071: Magic Attributes].
$childrenIf the [schema normalized value] PSVI property exists, a single text node whose string value is the value of that property.
Otherwise, the sequence of nodes constructed in the following way from the information items found in the [children] property: for each element, processing instruction, comment, and maximal sequence of adjacent characater information items found in the [children] property, a corresponding Element, Processing Instruction, Comment, and Text node is constructed.
Because the data model requires that all general entities be expanded, there will never be unexpanded entity reference information item children.
$typeThe xs:QName computed as described in
3.6 Mapping PSV Infoset additions to Types.
Note that if the type referenced would be a union type then
type refers to the member type that actually validated the
schema normalized value.
The unique ID of the element node is an identifier optionally assigned by the user. It corresponds to the [normalized value] property of the attribute information item in the [attributes] property that has a type ID, if one exists.
Note:
Using this definition, only IDs declared in a DTD are effective. See [Issue-0004: Schema/DTD]. Even so, this definition is not backward compatible with XPath 1.0. See [Issue-0038: XPath 1.0 treatment of non-unique IDs]. Furthermore, it doesn't even work as spec'd, see [Issue-0044: Unable to construct an element with unique ID].
The mapping of the data model to the XML Information Set maps an Element Node to an element information item. The properties of the element information item are constructed as follows:
| Property | Value: |
| [namespace name] | The namespace name of the QName returned by the dm:node-name accessor |
| [local name] | The local name of the QName returned by the dm:node-name accessor |
| [prefix] | An appropriate namespace prefix, as described below |
| [children] | The sequence of information items constructed from the nodes returned by the dm:children accessor. In other words, for each node returned by the dm:children accessor, a corresponding information item is constructed and that sequence of information items is used as the value for the [namespace name] property. |
| [attributes] | The sequence of attribute information items constructed from the nodes returned by the dm:attributes accessor. |
| [in-scope namespaces] | The sequence of namespace information items constructed from the nodes returned by the dm:namespaces accessor. |
| [base URI] | The value returned by the dm:base-uri accessor |
| [parent] | The information item constructed from the node returned by the dm:parent accessor. If the node has no parent, the property must be left absent and the resulting InfoSet will not be valid. |
| [namespace attributes] | The sequence of namespace information items constructed from the nodes that are present in the difference between the sequence of nodes returned by the dm:namespaces accessor on this element and the sequence of nodes returned by the dm:namespaces accessor of this element's dm:parent. |
An implementation must construct the value of the [prefix] property as if the following algorithm was applied: if the element has at least one namespace node whose namespace URI is the same as the namespace name of the QName returned by the dm:node-name accessor, it returns the local part of the name of that namespace node or the empty string if the namespace node has no name. If there are several such namespace nodes, it chooses one of them arbitrarily. If there is no such namespace node, it generates an arbitrary prefix that is distinct from the dm:node-name of any of the element's namespaces.
If a new prefix is generated, a corresponding namespace information item must be added to the [in-scope namespaces] property of the element information item. The namespace information item must associate the generated prefix with the namespace name of the QName returned by the element's dm:node-name accessor.
Note:
If the implementation has allowed in-scope namespaces to be discarded from the data model, then these namespaces may need to be reintroduced when creating an InfoSet in order to ensure that the InfoSet corresponds to a document that is namespace well-formed as defined in [XML Namespaces].
Note:
The algorithm used to calculate namespace attributes will need to be adjusted to cater for XML Namespaces 1.1, which allows the "undeclaration" of all namespaces, whether they have a prefix or not.
Attribute nodes encapsulate XML attributes. Attributes have the following properties:
node-name
parent
type, possibly empty
The above information associated with an attribute node is set during construction and can be accessed later via the accessor functions.
For convenience, the element node that owns this attribute is called its "parent" even though an attribute node is not a "child" of its parent element.
An attribute node can be constructed using dm:attribute-node which returns a new node with unique identity, distinct from all other nodes.
The constructor takes the attribute's expanded-QName, string value, and type.
dm:attribute-node( | $qname | as xs:QName, |
$value | as xs:string, | |
$type | as xs:QName) as AttributeNode |
Like all other node constructors, the attribute node constructor has the effect of creating a new node with a unique identity, distinct from all other nodes.
| Accessor | Returns: |
| dm:base-uri | () |
| dm:node-kind | "attribute" |
| dm:node-name | The QName of the attribute |
| dm:parent | The parent element node |
| dm:string-value | The value of the attribute |
| dm:typed-value | The typed value of the node |
| dm:type | Returns the QName of the attributes's globally declared type or the empty sequence if the attribute's type is locally declared or is unavailable |
| dm:children | () |
| dm:attributes | () |
| dm:namespaces | () |
| Editorial note | |
| The dm:string-value of a node and the result of casting the dm:typed-value of a node to a string may give different results under this definition. The issue of whether to allow or possibly mandate that dm:string-value return the same result as the string-value of the typed value is still under discussion. See [Issue-0079: String-value vs. string-value of the typed-value]. | |
When a data model fragment is created from the PSVI an attribute information item is mapped to an Attribute Node. The precise transformation is described by specifying the PSVI property corresponding to each argument of the attribute node constructor.
$qnameAn xs:QName constructed from the
[local name] property
and the
[namespace name] property
$valueThe [schema normalized value] PSVI property if that exists, or
the [normalized value] property.
$typeThe xs:QName computed as described in
3.6 Mapping PSV Infoset additions to Types.
Note that if the type referenced would be a union type then
type refers to the member type that actually validated the
schema normalized value.
The mapping of the data model to the XML Information Set maps an Attribute Node to an attribute information item. The properties of the corresponding attribute information item are constructed as follows:
| Property | Value: |
| [namespace name] | The namespace name of the QName returned by the dm:node-name accessor |
| [local name] | The local name of the QName returned by the dm:node-name accessor |
| [prefix] | An appropriate namespace prefix, as described below |
| [normalized value] | The value returned by the dm:string-value accessor |
| [owner element] | The information item constructed from the node returned by the dm:parent accessor. If the node has no parent, the property must be left absent and the resulting InfoSet will not be valid. |
| [specified] | The values of these properties are implementation-defined but must be consistent with the rest of InfoSet constructed. |
| [attribute type] | |
| [references] |
If the attribute node has a parent, an implementation must construct the value of the [prefix] property in the following way: if the attribute has a parent, in the same way that a prefix would be constructed for that element, otherwise a prefix is chosen arbitrarily, and no attempt is made to associate the prefix with the namespace URI.
Namespace nodes encapsulate XML namespaces. Namespaces have the following properties:
prefix, possibly empty.
uri
In XPath 1.0, namespace nodes were directly accessible by applications, by means of the namespace axis. In XPath 2.0 the namespace axis is deprecated, and it is not available at all in XQuery 1.0. XPath 2.0 implementations are not required to expose the namespace axis, though they may do so if they wish to offer backwards compatibility. The information held in namespace nodes is instead made available to applications using two functions defined in [Functions and Operators], namely xf:get-in-scope-namespaces and xf:get-namespace-uri-for-prefix. Certain properties of namespace nodes are not exposed by these functions: in particular, properties related to the identity of namespace nodes, their parentage, and their position in document order. Implementations that do not expose the namespace axis can therefore avoid the overhead of maintaining this information.
The above information associated with a namespace node is set during construction and can be accessed later via the accessor functions.
Each element node has an associated set of namespace nodes corresponding to its in-scope namespaces, and that element node acts as the parent of those namespace nodes.
A namespace node can be constructed using dm:namespace-node which returns a new node with unique identity, distinct from all other nodes.
The constructor takes a namespace prefix and the URI of the namespace being declared.
The namespace prefix may be the empty sequence. If the URI is the zero-length string, the prefix must be the empty sequence.
| Accessor | Returns: |
| dm:base-uri | fn:error, see [Issue-0087: base-uri should return ()?]. |
| dm:node-kind | "namespace" |
| dm:node-name | A QName with the namespace prefix in the local-name and an empty URI |
| dm:parent | () |
| dm:string-value | The namespace name (URI) of the node |
| dm:typed-value | () |
| dm:type | () |
| dm:children | () |
| dm:attributes | () |
| dm:namespaces | () |
When a data model fragment is created from the PSVI a namespace information item is mapped to a Namespace Node. The precise transformation is described by specifying the PSVI property corresponding to each argument of the attribute node constructor.
$prefixThe [prefix] property.
$uriThe [namespace name] property.
The mapping of the data model to the XML Information Set maps a Namespace Node to a namespace information item. The properties of the namespace information item are constructed as follows:
| Property | Value: |
| [prefix] | An appropriate namespace prefix, as described below |
| [namespace name] | The value returned by the dm:string-value accessor |
Processing instruction nodes encapsulate XML processing instructions. Processing instructions have the following properties:
target
content
parent, possibly empty
A processing instructoin node can be constructed using dm:processing-instruction-node which returns a new node with unique identity, distinct from all other nodes.
The constructor takes an NCName, a string, and an optional base URI.
dm:processing-instruction-node( | $target | as xs:NCName, |
$content | as xs:string) as ProcessingInstructionNode |
dm:processing-instruction-node( | $target | as xs:NCName, |
$content | as xs:string, | |
$base-uri | as xs:anyURI) as ProcessingInstructionNode |
The string '?>' may not occur within a processing instruction's target or content value ([XML Recommendation]).
| Accessor | Returns: |
| dm:base-uri | () |
| dm:node-kind | "processing-instruction" |
| dm:node-name | A QName with the processing-instruction target in the local-name and an empty URI |
| dm:parent | The parent element or document node |
| dm:string-value | The content of the processing-instruction |
| dm:typed-value | () |
| dm:type | () |
| dm:children | () |
| dm:attributes | () |
| dm:namespaces | () |
When a data model fragment is created from the PSVI, a processing instruction information item is mapped to a Processing Instruction Node. The precise transformation is described by specifying the PSVI property corresponding to each argument of the processing instruction node constructor.
$targetThe value of the [target] property.
$contentThe value of the [content] property.
$base-uriThe value of the [base URI] property.
There are no processing instruction nodes for processing instructions that are children of a document type declaration information item.
The mapping of the data model to the XML Information Set maps a Processing Instruction Node to a processing instruction information item. The properties of the processing instruction information item are constructed as follows:
| Property | Value: |
| [target] | The local name of the QName returned by the dm:node-name accessor |
| [content] | The value of the dm:string-value accessor |
| [parent] | The value of the dm:parent accessor. |
| [notation] | ??? UNKNOWN ??? |
| [base URI] | The value of the dm:base-uri accessor |
Comment nodes encapsulate XML comments. Comments have the following properties:
the content
parent
A comment node can be constructed using dm:comment-node which returns a new node with unique identity, distinct from all other nodes.
The constructor takes a string value.
The string "--" (two consecutive hyphens) must not occur within a comment's string value ([XML Recommendation]).
| Accessor | Returns: |
| dm:base-uri | () |
| dm:node-kind | "comment" |
| dm:node-name | () |
| dm:parent | The parent element or document node |
| dm:string-value | The content of the comment |
| dm:typed-value | () |
| dm:type | () |
| dm:children | () |
| dm:attributes | () |
| dm:namespaces | () |
When a data model fragment is created from the PSVI a comment information item is mapped to a Comment Node. The precise transformation is described by specifying the PSVI property corresponding to each argument of the comment node constructor.
$contentThe value of the [content] property.
There are no comment nodes for comments that are children of a document type declaration information item.
The mapping of the data model to the XML Information Set maps a Comment Node to a comment information item. The properties of the corresponding comment information item are constructed as follows:
| Property | Value: |
| [content] | The value of the dm:string-value accessor |
| [parent] | ??? WRONG: DM to Infoset Conversion!!! ??? The value of the dm:parent accessor |
Text nodes encapsulate XML character content. Text has the following properties:
content
parent
Text nodes must satisfy the following constraint:
A text node cannot contain the empty string as its content.
In addition, document and element nodes impose the constraint that two consecutive text nodes can never occur as adjacent siblings.
A text node can be constructed using dm:text-node which returns a new node with unique identity, distinct from all other nodes.
The constructor takes a string value.
| Accessor | Returns: |
| dm:base-uri | () |
| dm:node-kind | "comment" |
| dm:node-name | () |
| dm:parent | The parent element or document node |
| dm:string-value | The text content |
| dm:typed-value | The string value of the node as xs:anySimpleType |
| dm:type | () |
| dm:children | () |
| dm:attributes | () |
| dm:namespaces | () |
When a data model fragment is created from the PSVI a maximal sequence of consecutive character information items are mapped to a Text Node. The precise transformation is described by specifying the PSVI property corresponding to the argument of the comment node constructor.
$contentA string comprised of characters that correspond to the [character code] properties of each of the character information items.
Note:
The string-value is not W3C normalized as described in the Character Model for the World Wide Web version 1.0 draft. See [Issue-0045: Text nodes are not W3C-normalized text].
The mapping of the data model to the XML Information Set maps a Text Node to a sequence of character information items. The properties of the corresponding character information items are constructed as follows:
| Property | Value: |
| [character code] | The ISO 10646 character code of the character in question |
| [element content whitespace] | A boolean that is true if and only if the
entire Text Node consists of white space and the parent of the Text
Node exists and is an element and the element content type of the element is
not "mixed". [Issue-0088: Content type is not preserved] |
| [parent] |
[Definition: An
atomic value is a value in the value space
of an atomic type labeled with that
atomic type.] The typed value of nodes whose type is unknown
(for instance because they have not been validated)
are labeled with the type xs:anySimpleType.
[Definition: An atomic type
is a primitive simple type or a type derived by restriction from a primitive
simple type. Types derived by list or union are not atomic.]
The primitive simple types are those defined by XML Schema [XMLSchema Part 2]: xs:string, xs:boolean, xs:decimal, xs:float, xs:double, xs:duration, xs:dateTime, xs:time, xs:date, xs:gYearMonth, xs:gYear, xs:gMonthDay, xs:gDay, xs:gMonth, xs:hexBinary, xs:base64Binary, xs:anyURI, xs:QName, and xs:NOTATION. A derived atomic type is derived by restriction and has a primitive base type and a set of constraining facets.
| Editorial note | |
| Is "primitive" base type really what was intended? | |
The value space of the atomic values is the union of the value spaces of the nineteen primitive XML Schema types. This value space clearly includes those atomic values whose type is primitive, but it also includes those whose type is derived, as derivation by restriction always limits the value space.
An XML Schema simple type [XMLSchema Part 2] may be primitive or derived by restriction, list, or union.
The values of nodes whose type is an XML Schema primitive simple type or is derived by restriction from an XML Schema primitive simple type are represented as atomic values of that type.
The values of nodes whose type is derived by list from an XML Schema primitive type are represented by a sequence of atomic values whose type is the item type.
The values of nodes whose type is derived by union from an XML Schema primitive type are represented by a sequence of atomic values whose type is one of the individual types from the union. The union type information is lost and only the specific types of each individual item is retained.
An atomic value can be constructed from the value's lexical
representation. Given a string and an atomic type, the atomic value is
constructed in such a way as to be consistent with validation. In
particular the construction takes into consideration the facets of the
type. If the string does not represent a valid value of the type, an
error is raised. When xs:anySimpleType is specified as the type, no
validation takes place. The details of the construction are described
in the "Constructor Functions" and the related
"Casting Functions" section of [XQuery 1.0 and XPath 2.0 Functions and Operators].
A sequence is an ordered collection of zero or more items. An item may be a node or an atomic value, i.e. a sequence may contain nodes, atomic values, or any mixture of nodes and atomic values. When a node is added to a sequence its identity remains the same. Consequently a node may occur in more than one sequence and a sequence may contain duplicate items. Sequences are "flat", they may not contain other sequences.
An important characteristic of the data model is that there is no distinction between an item (a node or an atomic value) and a singleton sequence containing that item. An item is equivalent to a singleton sequence containing that item and vice versa.
Note:
Sequences replace node-sets