1.15.1 XQuery data model

The XQuery data model is a model for representing XML documents for processing by XQuery. The XQuery data model is a tree structure that holds nodes.

Nodes are of one of the kinds listed below. Each node also holds information in the form of properties.

A node or an atomic value is called an XQuery item. An ordered collection of zero or more XQuery items is called an XQuery sequence. Values are represented in the XQuery data model as XQuery sequences.

As an example, the figure below shows a tree representation of an XML document in the XQuery data model. The XQuery sequence corresponding to the example XML document includes only the document node inside the dotted lines in the figure. Because the document node designates the descendant nodes holding the contents of the XML document, the document node itself can be treated as representing the entire XML document.

XML document

<bookinfo book_id="310494321​">
 <category>programming</category>
 <title>Introduction to XML</title>
 <author>Sue Smith</author>
</bookinfo>

Figure 1-12 XQuery data model example

[Figure]

For the XML document shown in Figure 1-12, the result of the XQuery query /bookinfo/child::element() (extract the element node that is the child of the bookinfo element node), shown within the dotted lines in the figure, is an XQuery sequence consisting of three nodes.

Figure 1-13 Example of XQuery sequence consisting of nodes

[Figure]

For the XML document shown in Figure 1-12, the result of the XQuery query fn:data(/bookinfo/child::element()/text()) (extract the atomic value of the text node of the element node that is the child of the bookinfo element node), shown within the dotted lines in the figure below, is the XQuery sequence consisting of the three atomic values 'Programming', 'Introduction to XML', and 'Sue Smith'.

Figure 1-14 Example of an XQuery sequence consisting of atomic values

[Figure]

Organization of this subsection
(1) Order of nodes
(2) Property types
(3) Node details
(4) Parent-child relationships between nodes

(1) Order of nodes

Nodes are given an ordering, called document order. In document order, the XML elements and attributes of each node are considered to be in the order in which they appear in the XML document. The document order rules are as follows:

  1. Every node appears before any of its descendant nodes.
  2. An attribute node appears immediately following its associated element node.
  3. The order of siblings is the order in which they appear in the children property of the parent node.
  4. Descendant nodes appear before sibling nodes.

The following figure shows the document order given to the nodes of the tree in Figure 1-12:

Figure 1-15 Example of document order

[Figure]

(2) Property types

The following table lists the properties that nodes can have.

Table 1-44 Property types and their contents

No.Property nameExplanation
1node-nameQualified name of an XML element or XML attribute
2namespaceXML namespace to which the node belongs
3parentParent node
4childrenXQuery sequence of child nodes
5attributeXQuery sequence of attribute nodes
6type-nameQualified name of the XQuery data type of an XML element or XML attribute
7string-valueValue of the xs:string type character string representing the text that is specified as the node contents. See fn:string function.
8typed-valueValue of the XQuery data type obtained from the string-value property. See fn:data function.
9nilledProperty that indicates whether the contents of an XML element are empty. If the contents are empty, the children property does not contain any element nodes or text nodes.
10processing-instruction-targetThe application that is target of the XML processing instructions
11contentHolds the contents of an XML comment, XML element, or XML processing instruction

The property types that a node has depends on what kind of node it is. The table below lists the properties that each node has. For details about the properties of each node, see 1.15.1(3) Node details.

Table 1-45 Properties of each node

No.Property nameDocument nodeElement nodeAttribute nodeProcessing instruction nodeComment nodeText node
1node-nameNYYNNN
2namespaceNYNNNN
3parentNYYYYY
4childrenYYNNNN
5attributeNYNNNN
6type-nameNYYNNN
7string-valueYYYNNN
8typed-valueYYYNNN
9nilledNYNNNN
10processing-instruction-targetNNNYNN
11contentNNNYYY
Legend:
Y: Has the property.
N: Does not have the property.

(3) Node details

This subsection describes the six kinds of nodes that are in the XQuery data model.

(a) Document node

A document node holds the information for an XML document.

(b) Element node

An element node holds the information for an XML element.

(c) Attribute node

An attribute node holds the information for an XML attribute.

(d) Processing instruction node

A processing instruction node holds information for XML processing instructions.

(e) Comment node

A comment node holds information for an XML comment.

(f) Text node

A text node holds the information for the contents of an XML element.

(4) Parent-child relationships between nodes

The following tables indicate which kinds of nodes can act as the parent node or child nodes of which other kinds of nodes.

Table 1-46 Possible parent nodes for each kind of node

Node kindParent node kind
Document nodeElement nodeAttribute nodeProcessing instruction nodeComment nodeText node
Document nodeNNNNNN
Element nodeYYNNNN
Attribute nodeNYNNNN
Processing instruction nodeYYNNNN
Comment nodeYYNNNN
Text nodeYYNNNN
Legend:
Y: Can be parent node.
N: Cannot be parent node.

Table 1-47 Possible child nodes for each node kind

Node kindChild node kind
Document nodeElement nodeAttribute nodeProcessing instruction nodeComment nodeText node
Document nodeNYNYYY
Element nodeNYNYYY
Attribute nodeNNNNNN
Processing instruction nodeNNNNNN
Comment nodeNNNNNN
Text nodeNNNNNN
Legend:
Y: Can be a child node.
N: Cannot be a child node.