Saturday, May 24, 2014

XQuery Basics: XQuery Data Model Overview

Last several blog posts, we learned the basic of XPath expression, and how to convert XML data to tabular format using OPENXML function. Now, we'll learn XQuery(XML Query Language). As current version of XPath, XPath expressions only allow retrieve data from XML document or fragment. XQuery however, allow retrieval, sort, update, delete, loop, conditional branch, create customized functions, etc... Basically SQL is for query relational database, XQuery is for querying XML document or XML database.

Before writing our first XQuery query, let's go over XQuery Data Model. It's important to learn the XQuery data model, because it helps us learning XQuery. For example, when learning SQL it's beneficial to know the basic concepts of relational database such as table, column, row, constraint, data type, index, relationship between tables, etc.

You can read more about the W3C XQuery and XPath Data Model 3.0 here.
Here's the summary straight out W3C XQuery and XPath Data Model 3.0 document.

Every instance of the data model is a sequence.
A sequence is an ordered collection of zero or more items. Note: a sequence cannot be a member of a sequence.
An item is either a node, a function, or an atomic value.
There're 7 kind of nodes:
  document, element, attribute, text, processing instruction, comment, and namespace.
A function is an item that can be called. A list of XQuery Functions can be found here.
An atomic value is a value of an atomic type.
An atomic type is a primitive simple type or a type derived by restriction from another atomic type.
There're 21 built-in primitive simple types:
   string, boolean, decimal, float, double, duration, datetime, time, date, gYearMonth, gYear, gMonthDay, gDay, gMonth, hexBinary, base64binary, anyURI, QName, NOTATION.

The following pictures provide summary for the W3C XQuery and XPath Data Model 3.0

Images source: W3C XQuery and XPath Data Model 3.0

W3C XQuery and XPath Data Model 3.0
XQuery Reference
XQuery Functions for XML data type
XQuery 3.0 from W3C

No comments:

Post a Comment