Data Model
XQuery's data model describes the values that occur in the evaluation of a query; the inputs, outputs and intermediate values that occur during the processing of a query are all instances of the data model. The XQuery data model contains these important categories of values:
Simple Typed Values. A simple typed value conforms to a simple type as defined by the XML Schema specification, which includes strings, integers, dates etc. You can find the complete list of simple types in the
XML Schema specificationPart 2.
Nodes. The XQuery data model recognizes seven types of nodes:
document, element, attribute, text, comment, processing-instruction and
namespace nodes. The model treats XML documents and document fragments as trees of nodes. A document is a tree with the document node as the root of the tree. Similarly a document fragment is a tree with an element at its root. Document nodes and namespace nodes have no parents. All other nodes can have zero or one parent. Only a document node or an element node can have children. Here's a simple xml document and the corresponding data model instance.
<?xml version="1.0"?>
<greetings>
<!Welcome message -->
<welcome>Hello XQuery User</welcome>
</greetings>
The data model instance representing this document looks like
Figure 1:
 | |
| Figure 1: The data model representing a simple XML document containing a <greeting> root element and a <welcome> element that holds a text message. |
Sequences. A sequence is an ordered list of simple values or nodes. Sequences are flat, which means that a sequence cannot contain another sequence as its member. A sequence containing only one member is referred to as a
singleton sequence. From a data model point of view, there is no distinction between a singleton sequence containing a simple value and the simple value itself.
Query Expressions. Expressions are the top-level abstraction of every element in XQuery, and are the basic building blocks of XQuery. There are several kinds of expression defined in the latest specification:
- Constants and Variables
- Operators
- Path Expressions
- FLWR (For-Let-Where-Return) expressions
- Element/Attribute Constructors
- Conditional expressions
- Quantified Expressions
- Built-in and User Defined Functions