# Presentation: 116595

## XQuery Update 

**Michael C****hampion**
- Software AG
- June 16, 2004

## Outline

- Background
- Present Status
- Future Prospects

- Introduction to XQuery

## Why XQuery?

**Internet connects diverse data sources and creates demand for queries across them**
**Much of that data is "unstructured" or "semi-structured"**
**XML is the neutral format widely used to exchange data across systems, applications, languages**
**SQL is not well-suited to XML**

- RDBMS

- XML
- DBMS

- Docs

- Apps

**?**

- Enterprise
- Systems

- Introduction to XQuery

## XQuery Unifies Diverse Approaches

**Data model can represent diverse data**
**Handles XML's order, hierarchies**
**Allows strong typing of data or treating XML as text**
**An XML programming language, not just "query" language**

- Introduction to XQuery

**Notes:**
The heart of Tamino XML Server is the server core, principally the server engine. Tamino has (among others) 2 key strengths:

 It is simple
 It is based on open standards

It is simple
From the beginning access to data held in Tamino was designed to be simple.
All objects stored in Tamino are referenced by URL – the entry point to Tamino is via HTTP / TCP/IP. Nothing could be simpler.
To “speak” to Tamino you just require a standard browser.
This simple interface is attractive not only to end-users, but also to 3rd parties such as Content Management vendors building on Tamino as the underlying engine for their systems. Many have quoted this “simplicity” as a major “winning” factor.

Tamino is also “simple” in the way in which it stores XML documents – they go in “as-is”. No conversion is required. This is native storage.

Tamino is open
There is a strong move towards open standards in the IT industry. Tamino is entirely based on open standards.
To query documents, you can use either the W3C XPath or XQuery standards. The principle interface is HTTP (open standard).
Tamino provides full support for XML DTDs and XML Schemas including built-in validation.

Tamino is also open in that it comes with a whole array of high-level interfaces allowing developers to choose their programming language of choice when building applications accessing data in Tamino. Tamino is quite agnostic here – the two major communities (Java and Microsoft) are equally well supported.
The EJB API actually gives transactional control over Tamino to the EJB container itself – you cannot be more open than this.
This is typical of Tamino. It fits into existing infrastructures (Web Servers, Application Servers, Integration software) – and this is what customers are looking for – open, standards-based software that helps them get the job done while being as unobtrusive as possible.

Tamino is also open as regards data formats. Tamino can not only store XML documents but also any kind of non-XML (word processing files, videos, graphics etc.). And the powerful indexing options allow programmers not only to perform efficient searches on XML structures and tags but also include out-of-the-box fulltext search capabilities and (as a special professional services offering) also the indexing of non-XML documents – enabling applications to search across XML and non-XML (e.g. Word files) in the same way.
And finally Tamino also comes with a full-blown SQL engine (particularly of interest to ISVs who require both and SQL and XML repository for their applications).

Of course Tamino has many more features, the main thing to remember though is that Tamino is a highly efficient storage and management tool for XML and associated data based on open standards and offering ease of access.

## XQuery and SQL

**We're living through an epochal moment in the history of the industry. The hybridization of SQL and XML will deeply transform the philosophy and practice of data management in ways that I think none of us fully understands – Jon Udell **
**SQL-XML**
- 1st edition an official ISO standard
- Provides mapping between SQL and XML schema types
- “barely a good start” according to Jim Melton

- Introduction to XQuery

## XQuery and XSLT

- XPath 2.0 is a subset of XQuery; everything but
- element and attribute constructors
- function definitions
- strong typing
- XSLT has very similar functionality
- Most of the XQuery example queries can be done with XSLT 1.0
- XSLT 2.0 also based on XPath
- The XQuery approach is almost certainly easier for SQL developers to pick up

- Introduction to XQuery

## Basic FLWOR expression

**for **
- Iteration on sequence
- Item variables
**let**
- Sequence variable
**where **
- Filter on variables
- Often equivalent to predicates in path expressions
**order by**
- Sorts the results before return
**return **
- Result construction

**for****	****$b ****in**** input()/bib/book**
**let****	****$a := $b/author **
**where****	****$b/price ****lt**** 200**
**order by   $a**
**return****	****($b/title,  $a)**

- Introduction to XQuery

**Notes:**

where filter versus predicates in path expressions: 
Example for redundancy because of several languages in one
Some subtle differences
Input order versus Document order
Better typed value comparison versus general comparison

## Constructors

**Constructs new nodes to hold information returned from a query**
- Appears to wrap output in XML markup
- Actually creates XQuery data model nodes
**Curly braces { } delimit expressions that are evaluated and their result inserted**
***Allow XSLT-like transformations!***

**let $a := input()/bib/book/author**
**return**
**  ****<index type="author">**
**    ****{ $a/last }**
**    ****{ $a/first }**
**  ****</index>**

- Introduction to XQuery

## Current Status

**Last Call Working Draft**
- WG analyzing comments from outside reviewers
**Implementations**
- W3C lists 31 implementations, about half commercial products
**APIs**
- Numerous product-specific APIs
- Microsoft support in “Whidbey” version of System.XML classes
- JSR-000225 XQuery API for Java (XQJ)
**Test Suites**
- NIST suite
- W3C
- Bumblebee

- Introduction to XQuery

## XQuery 1.0 is "Read Only"

- No capability for data manipulation operations such as  SQL INSERT, UPDATE, DELETE
- Currently planned for XQuery 1.1; Requirements draft has been published
- XML DB vendors get strong customer demand for these features, and all add their own extensions.
- Many extensions are based on
- Patrick Lehti *Design and Implementation of a Data Manipulation Processor for an XML Query Language*.  http://www.lehti.de/beruf/ diplomarbeit.pdf

- Introduction to XQuery

## Future Prospects

**Finalize XQuery Recommendation!**
- Mid-2005?
- XQJ will follow soon after
**XQuery 1.1**
- Requirements have been drafted
- Update, full-text search

- Introduction to XQuery

## Tamino update extensions

**update delete input()/reviews/entry/review/text()**

**update replace input()/bib/book/title[. = "TCP/IP Illustrated" ]**
** ****with <title>TCP/IP Illustrated I. The Protocols</title>**

**update insert**
**<book year="2001">**
**  ****<title>XML Schema Part 0: Primer</title>**
**  ****<editor>**
**    ****<last>Fallside</last> <first>David C.</first>**
**</editor>**
**  ****<publisher>World Wide Web Consortium</publisher>**
**</book>**
**into input()/bib**

- Introduction to XQuery

**Notes:**

where filter versus predicates in path expressions: 
Example for redundancy because of several languages in one
Some subtle differences
Input order versus Document order
Better typed value comparison versus general comparison

## Full Text Search

- Will not be in XQuery 1.0, targeted for 1.1
- Requirements and use cases have been published
- Problems apparently related to internationalization issues
- Text search usually implies operations on words, sentences, and paragraphs
- Is a language-neutral definition of these concepts possible?** **

- Introduction to XQuery

## Further enhancements?

**GroupBy**
**Exceptions**
**Duplicate elimination**
**Web services invocation**
**Thesaurus / Taxonomy / Ontology guided queries**

- Introduction to XQuery

## Ongoing Reality Check

**Real interoperable standard, or another SQL?**
**Will SQL-XML co-opt it in the mainstream?**
**Will APIs converge the way the SQL APIs did?**
**Will performance be a concern?**
- Initial performance concerns for new technologies overstated
- Competition gets the creative juices flowing (e.g. compilers)
- Many DB optimizations don’t depend on relational model
- Moore’s Law ...
- But:
- XQuery inherently less parallelizable than SQL
- XML itself imposes some overhead
- XQuery use cases are intrinsically hard problems!

- Introduction to XQuery

## Wrapup: XQuery for Information Integration

**Wrapup: XQuery for Information Integration**

- RDBMS

- XML DB

- RDBMS

- Web Services

- XQuery

**Applications ****as Services**

- Introduction to XQuery

## Thank You!

**For more information, see**
- _[http://www.w3.org/TR/xquery](http://www.w3.org/TR/xquery)_
- The current draft of the spec itself
- _[http://www.w3.org/XML/Query#products](http://www.w3.org/XML/Query#products)_
- A list of implementations
- _[http://xml.coverpages.org/xmlQuery.html](http://xml.coverpages.org/xmlQuery.html)_
- Summaries and links to all sorts of XQuery resources
- _[http://](http://www.xmlstarterkit.com/)__[www.xmlstarterkit.com](http://www.xmlstarterkit.com/)__[/](http://www.xmlstarterkit.com/)_
- Software AG’s XML server implementing XQuery
- http://www.xquery.com
- Tutorials, home of Bumblebee
- http://www.saxonica.com
- Saxon is most highly regarded open source XQuery implementation
- mailto:// _[mike.champion@softwareagusa.com](mailto:mike.champion@softwareagusa.com)_
- Other questions or followups

- Introduction to XQuery

## Slide 18

- Introduction to XQuery