Nonstop Database, HiRDB Version 9 SQL Reference

[Contents][Index][Back][Next]

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 name Explanation
1 node-name Qualified name of an XML element or XML attribute
2 namespace XML namespace to which the node belongs
3 parent Parent node
4 children XQuery sequence of child nodes
5 attribute XQuery sequence of attribute nodes
6 type-name Qualified name of the XQuery data type of an XML element or XML attribute
7 string-value Value of the xs:string type character string representing the text that is specified as the node contents. See fn:string function.
8 typed-value Value of the XQuery data type obtained from the string-value property. See fn:data function.
9 nilled Property 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.
10 processing-instruction-target The application that is target of the XML processing instructions
11 content Holds 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 name Document node Element node Attribute node Processing instruction node Comment node Text node
1 node-name N Y Y N N N
2 namespace N Y N N N N
3 parent N Y Y Y Y Y
4 children Y Y N N N N
5 attribute N Y N N N N
6 type-name N Y Y N N N
7 string-value Y Y Y N N N
8 typed-value Y Y Y N N N
9 nilled N Y N N N N
10 processing-instruction-target N N N Y N N
11 content N N N Y Y Y

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 kind Parent node kind
Document node Element node Attribute node Processing instruction node Comment node Text node
Document node N N N N N N
Element node Y Y N N N N
Attribute node N Y N N N N
Processing instruction node Y Y N N N N
Comment node Y Y N N N N
Text node Y Y N N N N

Legend:
Y: Can be parent node.
N: Cannot be parent node.

Table 1-47 Possible child nodes for each node kind

Node kind Child node kind
Document node Element node Attribute node Processing instruction node Comment node Text node
Document node N Y N Y Y Y
Element node N Y N Y Y Y
Attribute node N N N N N N
Processing instruction node N N N N N N
Comment node N N N N N N
Text node N N N N N N

Legend:
Y: Can be a child node.
N: Cannot be a child node.