ou can find a quick introduction to the XQuery language with examples of several kinds of XQuery expressions in Part I of this series. In this part you'll explore some basic XQuery concepts.
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
. The XQuery data model recognizes seven types of nodes: document, element, attribute, text, comment, processing-instruction
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.
<!Welcome message -->
<welcome>Hello XQuery User</welcome>
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.|
. 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.
. 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
- Path Expressions
- FLWR (For-Let-Where-Return) expressions
- Element/Attribute Constructors
- Conditional expressions
- Quantified Expressions
- Built-in and User Defined Functions