The XQuery Data Model

The XQuery Data Model is based on the XML Information Set, often called the Infoset. The XML Information Set Recommendation is described at http://www.w3.org/TR/xml-infoset/.

The Infoset is intended to provide an abstract representation of XML documents (or the most important parts of them) and is intended for use by other XML specifications. The XQuery 1.0 and XPath 2.0 Data Model will be built on the infoset.

The XQuery Functions and Operators

The XQuery 1.0 and XPath 2.0 Functions and Operators document lists, in abstract terms, are an extensive range of functions and operators that will be available for use in XQuery 1.0 and XPath 2.0 (and also XSLT 2.0). Not every function needs to be used in any particular language.

The range of functions provided substantially extends what was available in XPath 1.0, even with the addition of the functions provided by XSLT 1.0. Because XQuery is strongly datatyped, it becomes both possible and necessary to augment the range of functions that can handle specific data types, particularly those data types allowed by XSD Schema but not recognized among the four XPath 1.0 data types.

For example, XQuery will provide an extensive range of functions and operators that will operate on date-related data types. The current working draft lists more than twenty functions that operate specifically on date/time values. These are divided into three groups—duration and datetime constructors, comparisons of duration and datetime values, and, finally, component extraction functions on datetime values.

XSD Schema provides nine datetime data types— xsd:duration, xsd:dateTime, xsd:date, xsd:time, xsd:gYear, xsd:gYearMonth, xsd:gMonthDay, xsd:Month, and xsd:Day.

The functions and operators are currently presented in an abstract syntax such as xf:date and op:numeric-add. The implemented syntax within XQuery, XQueryX, XPath 2.0, and XSLT 2.0 might vary.

Note

The indicative namespace prefix for XQuery functions is xf. This indicative namespace prefix refers, for the working draft current at the time of writing, to the URI http://www.w3.org/2001/12/xquery-functions. XQuery operators have an indicative namespace prefix of op that relates to the namespace URI http://www.w3.org/2001/12/xquery-operators.


One example of a duration and datetime constructor function is the xf:duration function, which takes a string argument and creates a result that is of xsd:duration data type. If the string argument does not correspond to the xsd:duration type, an error is raised. Similarly, the xf:date function takes a string argument and returns a result that is of xsd:date data type.

The functions that perform comparisons on xsd:dateTime and xsd:duration values have a number of limitations but are, nonetheless, very useful additions to what was available in XPath 1.0. These functions are, because of limitations in XSD Schema 1.0, able to return only an xsd:boolean value after performing a comparison. Additionally, only certain datetime constructs can be taken by these functions as arguments. The argument to these functions must be either of the form that contains only years and months or of the form that contains days, hours, minutes, and seconds.

For example, the op:duration-less-than() operator takes two arguments and returns an xsd:boolean value.

The component extraction functions treat a datetime value as if it were constructed of distinct components. Intuitively this makes sense. A date value of 2003-01-15—corresponding to January 15, 2003—has three components, a year, a month, and a day.

For example, the xf:get-Century-from-dateTime() function can take an argument of xsd:dateTime data type and return an integer value corresponding to the century part of the xsd:dateTime data type. If we use the xf:get-Century-from-dateTime() function as in this code,

xf:get-Century-from-dateTime(xf:dateTime('2003-01-15T15:35:00')) 

it will return the integer value 20. The xf:dateTime() function converts the string argument to an xsd:dateTime data type, which is the legal argument data type for the xf:get-Century-from-dateTime() function.

Caution

Be careful to distinguish the century returned by xf:get-Century-from-dateTime() from the common English means of the expression of century. When we would talk of the twenty-first century, the function will return the integer value of 20.


If, however, the string we want to use corresponds to the xsd:date data type, 2003-01-15 for example, we must use a separate function xf:get-Century-from-date() function as shown here:

xf:get-Century-from-date(xf:date('2003-01-15')) 

As you have hopefully seen from these brief examples, XQuery 1.0 provides new functions not present in XPath 1.0 or XSLT 2.0. There will likely be dozens of new functions. Those quoted give you an indication of the functions likely to be available. Datatyping provides useful new functionality, but the strict datatyping means that you will need to have a good working understanding of the differences between the relevant XSD Schema data types and which are legal arguments for which XQuery function(s).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.144.18