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"> |
Figure 1-12 XQuery data model example
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
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
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:
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
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 |
This subsection describes the six kinds of nodes that are in the XQuery data model.
A document node holds the information for an XML document.
Property name | Explanation |
---|---|
children | XQuery sequence of child nodes of the document node |
string-value | Value of the result of concatenating, in document order, the values of the content properties of the descendant text nodes, or a character string of length zero if there are no text nodes descendants |
typed-value | Value of the string-value property as an xs:untypedAtomic type |
An element node holds the information for an XML element.
Property name | Explanation |
---|---|
node-name | Indicates the qualified name of the XML element. |
parent | Indicates the parent node of the element node. The parent node can be either a document node or an element node. |
type-name | Indicates the XQuery data type of the element node. If XML schema validation is not performed, or if XML schema validation results in an element type name that does not correspond to an XQuery data type provided by HiRDB, the value of the type-name property is undefined. |
children | Indicates the XQuery sequence of child nodes of the element node. |
attribute | Indicates the XQuery sequence of attribute nodes for the element node. |
namespace | Indicates the XML namespace to which the element node belongs. |
nilled | Indicates whether the contents of the element node are empty. If the contents are empty, the children property does not contain any element nodes or text nodes. |
string-value | Indicates the result of concatenating, in document order, the values of the content properties of the descendant text nodes. If the contents of the element are empty, the value of this property is a character string of length zero. |
typed-value | If the value of the type-name property is undefined, this is the actual value of the string-value property as an xs:untypedAtomic type. If the XML element is empty, the value of this property is an empty XQuery sequence. Otherwise, it is an XQuery sequence of atomic values obtained from the value of the string-value property based on the XQuery data type of the type-name property. |
An attribute node holds the information for an XML attribute.
Property name | Explanation |
---|---|
node-name | Indicates the qualified name of the XML attribute. |
parent | Indicates the parent node of the attribute node. The parent node is the node of the elements to which the XML attributes belong. |
type-name | Indicates the name of the XQuery data type of the attribute node. |
string-value | Indicates the values held by the attribute node. This property cannot be empty. |
typed-value | If type-name is xs:untypedAtomic, this is the actual value of the string-value property as an xs:untypedAtomic type. Otherwise, it is an XQuery sequence of atomic values obtained from the string-value property based on the XQuery data type resulting from validation against the XML schema. |
A processing instruction node holds information for XML processing instructions.
Property name | Explanation |
---|---|
processing-instruction-target | Indicates the target to which the processing instructions are applied. |
content | Indicates the contents of the processing instructions. |
parent | Indicates the parent node of the processing instruction node. |
A comment node holds information for an XML comment.
Property name | Explanation |
---|---|
content | Indicates the contents of the XML comment. |
parent | Indicates the parent node of the comment node. |
A text node holds the information for the contents of an XML element.
Property name | Explanation |
---|---|
content | Indicates the character string contents of the XML element. |
parent | Indicates the parent node of the text node. |
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 |
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 |