Apr 19, 2008

XQuery Java API (tutorial)

This API provides the methods for compiling and executing XQuery/XPath scripts from Java and exploiting the results. This is very similar to using the SQL language through a Java interface like JDBC.
Using XQuest's implementation of XQuery provides a high-level query language and extended processing capabilities. It is therefore advisable to implement the largest possible part of an application with XQuery, and use Java only for retrieving final results. This is especially true when connecting to a remote server, because such an approach will likely minimize the network traffic.
The API is actually used in the GUI and Command-line Interface applications provided with XQuest, as well as in the "Server Pages" extension, which embeds the XQuery engine in a Servlet.

The API allows:
• Creation and setup of a compilation and execution environment (which implements both the static context and dynamic context defined in the XQuery Specifications). These environments are basically provided by an interface named XQueryConnection Creation of Expressions from a XQueryConnection (interfaces XQueryExpression and XQueryPreparedExpression ). Such expressions are similar to Statements found in database connectivity interfaces like JDBC. Expressions receive a Query (i.e. a XQuery script) which is compiled and then executed once or several times.

An Expression is itself a context which inherits the environment provided by the connection, and can then be set up individually before execution. In particular, it is possible to bind global variables of the XQuery expressions to initial values.

• Exploitation of results of Expression evaluations.

The result sets are iterators, since the XQuery/XPath2 language can generally return se- quences of Items. Items are either atomic values (such as numbers or strings), or Nodes, which describe the structure of XML documents and data. The properties and relationships of Nodes are de- scribed in a section of the XQuery/XPath2/XSLT2 specifications which is called the Data Model. A section of the present document is dedicated to the Data Model interfaces, which handle Nodes.

For calling Java methods from within XQuery expressions, see the Java Binding section of the XQuery Extensions documentation.
For dealing specifically with XML databases (XML Libraries), see the XML Library API


Download

0 comments: