The XQuery API for Java (XQJ
), is currently under development through the Java Community Process as JSR 225. It provides Java programmers and easy way to use XQuery for XML programming and data integration, with full access to the J2SE and J2EE platforms. XQJ allows a Java program to connect to XML data sources, prepare and issue XQueries, and process the results as XML. This functionality is similar to that of JDBC Java API for SQL, but the query language for XQJ is XQuery. A new XQJ tutorial covers how to use the XQuery API for java, starting with a simple XQuery/XQJ version of the familiar "Hello World!" application, this XQJ tutorial teaches you the following topics in detail:
Introduction to XQJ
Using an XQuery/XQJ version of the familiar "Hello World!" application, this tutorial introduces you to some of the similarities between XQJ and JDBC, including connections and datasources, as well as some of the concepts that make XQJ different from JDBC, including data models, typing, and error handling.
Configuring XQJ Connections
An XQJ application always starts with accessing an XQDataSource object. The XQDataSource object encapsulates all the parameters and settings needed to create a session with a specific implementation, and eventually execute XQuery expressions and process results. This tutorial describes how to work with the XQDataSource object in an XQJ application.
Querying Data from XML Files or Java XML API
In XQJ, XQExpression objects allow you to execute XQuery expressions. In this tutorial, you'll learn how to use XQExpression objects to query data, and how to use prepared queries to reduce expensive parsing and validation operations.
Processing Query Results
In XQuery, query evaluation results in a sequence. This tutorial describes how to use the XQJ XQSequence object, which represents an XQuery sequence and a cursor to iterate over the sequence.
Serializing XQuery Results
This tutorial shows you how to serialize query results as XML, and how to use HTML and XHTML output methods for results. You'll also learn how to serialize results to java.io.Writer and getSequenceAsString() using the writeSequence() method.
How to Manipulate Static Context
Some information — the default element namespace, default order for empty sequences, the base URI, for example — becomes available before an XQuery expression is evaluated. This information, referred to as the static context, can be accessed through the XQJ API. This tutorial describes the static context in greater detail, and shows how to use XQJ to manipulate it.
The XQuery Type System
XQuery is a strongly typed language, with a type system based on XML Schema. This tutorial describes how to use the XQSequenceType and XQItemType XQJ interfaces to interact with the XQuery type system.
Binding External Variables
Continuing from the previous tutorial on Querying Data from XML Files or Java XML APIs, this tutorial discusses the topic of binding variables in greater detail. Need to convert a Java object in your Java application into an XDM instance? XQJ defines this mapping and glues it all together.
Creating XDM Instances
XQJ offers functionality to create both XQSequence and XQItem objects, not as a result of a query execution, but rather as standalone XDM instances. Read this tutorial and learn more about the flexibility of creating XDM instances outside query execution using XQJ.
An XML pipeline is a sequence of XML processes, also called transformations; in a pipeline, the result of one transformation is passed as input to the next one. In this tutorial, you'll learn how to create a pipeline of XQueries and how to integrate XQuery with JAXP-based XML processors.
Processing Large XML Input Files
Since XML became a standard in the late 90's, we have been taught that XML is a tree; and the most intuitive (and popular) representation of such a tree has been (and still is!) the Document Object Model (DOM). But the DOM has limitations, especially where performance and scalability are concerned. This tutorial shows you how to take advantage of streaming processors, like the one available from DataDirect XQuery.
The XQJ Tutorial introduces a number of technologies and techniques for developing XQuery applications using XQJ. We've compiled a short list of useful resources for those who want to do more self-guided exploration on XQJ and related topics.