Basic Principles, Lesson 1
The XQuery Data Model

Lesson Scenario

All the lessons in this Primer are based on a real-world scenario.

XQuery Data Model

XQuery uses an XML data model that can represent XML documents, sequences, or atomic typed values (such as integers or strings). For example, an XML document is represented as a tree of nodes, including a document node, element nodes, attribute nodes, comment nodes, and text nodes. Both the input and the output of any query are represented in this data model.

In the XQuery Data Model, an XML document is represented as a tree of nodes. The first node is the document node, which represents the document itself. The document node is the root of a tree that contains the rest of the document. The tree contains a node for each element, attribute, span of text, processing instruction, or comment in the document. In addition, the XQuery Data Model allows single values.

Using our lesson scenario, suppose the purchase order from the retailer, once converted into XML, looks something like this:


<?xml version="1.0"?>
<invoicecollection>
    <invoice>
        <customer>Wile E. Coyote, Death Valley, CA</customer>
        <annotation>Customer asked that we guarantee return rights if these items
        should fail in desert conditions. This was approved by Marty
        Melliore, general manager.</annotation>
        <entries n="2">
            <entry quantity="2" total_price="134.00">
                <product maker="ACME" price="80.00" prod_name="atomic hammer">
		</product>
            </entry>
            <entry quantity="1" total_price="20.00">
                <product maker="ACME" price="20.00" prod_name="power springs">
		</product>
            </entry>
        </entries>
    </invoice>
    <invoice>
        <customer>Camp Mertz</customer>
        <entries n="2">
            <entry quantity="2" total_price="32.00">
                <product maker="BSA" price="16.00" prod_name="left-handed smoke
		shifter">
                </product>
            </entry>
            <entry quantity="1" total_price="13.00">
                <product maker="BSA" price="13.00" prod_name="snipe call">
		</product>
            </entry>
        </entries>
    </invoice>
</invoicecollection>

The following diagram shows how the XQuery Data Model represents the XML that describes the retailer's purchase order. Examples of the document node, an element node, and an attribute node are labeled. For simplicity, values are not shown.

Node Graphic

Summary

In the XQuery Data Model, XML is represented as a tree of nodes. This allows XQuery to work on any kind of XML data, whether it is native XML or an XML view.

Next Lesson


Copyright © 1993 - 2008. Progress Software Corporation. All rights reserved. | N. America: 800 876 3101 | World: +44 (0) 1753 218 930