The use of XML has become ubiquitous over the last five years, and thus a huge amount of data is now stored in XML, both as databases and as documents. XML data can include highly structured data such as sales figures, less structured data such as product catalogs, and unstructured data such as books. With such a variety of data stored as XML, in each case different elements of the data must be formatted and transformed in a particular way. This is where XQuery comes in. It is a query language that allows the user to select those XML data elements of interest, reorganize them, transform them, and finally return the results in a data structure. This book acts as an up-to-date tutorial and reference on this useful technology. There are plenty of examples shown that illustrate the concepts being presented. The following is a detailed description of the book's contents:
1. Introduction to XQuery - Provides the basic purpose and capabilities of XQuery and also acts as a quick introduction to its features. It provides a basic familiarity with the most commonly used kinds of expressions, without getting too bogged down in the details.
2. XQuery Foundations - a brief overview of the foundations of XQuery including its design, its place among XML-related standards, and its processing model. It also discusses the underlying data model behind XQuery and the use of types and namespaces in queries.
3. Expressions: XQuery Building Blocks - The basic unit of evaluation in XQuery is the expression. A query contains expressions that can be made up of a number of sub-expressions, which may themselves be composed from other sub-expressions. This chapter explains the XQuery syntax, and covers the most basic types of expressions that can be used in queries: literals, variables, function calls, and comments.
4. Navigating Input Documents Using Paths - Path expressions navigate input documents to select elements and attributes of interest. This chapter explains how to use these path expressions to select elements and attributes from an input document and apply predicates to filter those results. It also covers the different methods of accessing input documents.
5. Adding Elements and Attributes to Results - Queries often include some XML elements and attributes that structure the results. This chapter explains how you can create entirely new elements and attributes and include them in your results.
6. Selecting and Joining Using FLWORs - Describes the facilities in XQuery for selecting, filtering, and joining data from one or more input documents. Included is the syntax of FLWORs (for, let, where, order by, return) and quantitative expressions.
7. Sorting and Grouping - How to sort and group data from input documents. This chapter covers sorting in FLWORs, grouping results together, and calculating summary values using the aggregation functions.
8. Functions - Describes this useful feature of XQuery that allow a wide array of built-in functionality, as well as the ability to modularize and reuse parts of queries. There are two kinds of functions: built-in functions and user-defined functions, and this chapter looks at them both.
9. Advanced Queries - Describes syntax and techniques for some commonly requested query capabilities by showing you some creative ways to apply XQuery syntax.
10. Namespaces and XQuery - The first part provides a refresher on namespaces in XML input documents in general. Next the use of namespaces in queries is covered including how to declare and refer to them and how to control their appearance in your results.
11. A Closer Look at Types - Goes into detail on the set of built-in types in XQuery. A good explanation of the automatic type conversions performed by the processors and a description of the expressions that are relevant to type constructors, cast and castable expressions, and instance of expressions.
12. Queries, Prologs, and Modules - Discusses the structure of queries starting with the query prolog and its various declarations. The assembly of queries from multiple modules, declaration of global variables, and definition of external functions is then tackled.
13. Using Schemas with XQuery - Provides a brief overview of XML Schema. Discusses how schemas are used with queries by importing schema definitions and taking advantage of schema-defined types.
14. Static Typing - Static typing in XQuery means reporting all possible type errors at compile time instead of run time. Discussed in the context of aggressive error reporting.
15. Principles of Query Design - Discusses the goals of query design with particular attention paid to handling errors and tuning for performance.
16. Working with Numbers - Describes the four major numeric types, along with the operators and functions that act on numeric values. The operators include comparisons and arithmetic operations. The functions that operate on numeric values that are discussed include round and sum.
17. Working with Strings - Discusses constructing and comparing strings and provides an overview of the built-in functions that manipulate strings. It also explains related features such as whitespace handling and internationalization.
18. Regular Expressions - Probably already a familiar concept to the Unix-aware, this discusses the topic in context of the XQuery language.
19. Working with Dates, Times, and Durations - Explains the eleven date-related types used in XQuery and the functions and operators that act on them.
20. Working with Qualified Names, URIs, and IDs - Each of these types has unique properties and complexities that sets it apart from simple strings. Describes the functions and constructors that act on them.
21. Working with Other XML Components - Discusses comments, processing instructions, documents, and text nodes. CDATA sections and XML character and entity references are also covered in this chapter.
22. Additional XQuery-Related Standards - Discusses serialization, XQueryX, XQuery Updates, Full-Text search, and XQJ. These are peripheral standards that complement, but are not central to, the XQuery 1.0 language.
23. Implementation-Specific Features - Looks at some of the implementation-specific aspects of XQuery that provide customized functions and settings for specific use cases.
24. XQuery for SQL Users - Provides information for readers who are already using SQL and relational databases. It compares SQL and XQuery and also shows how to use them together.
25. XQuery for XSLT Users - The similarities and differences between XQuery and XSLT. This chapter also shows XSLT 1.0/XPath 1.0 users the differences and compatibility problems when moving to XQuery/XPath 2.0.
A. Built-in Function Reference
B. Built-in Types
C. Error Summary