Subject:New XQJ Tutorial and Example Files Author:SSDN Admin Date:10 May 2005 03:48 PM
The XQuery language is designed specifically for XML programming and data integration, and programmers are more productive using XQuery for these tasks. However, many enterprise applications are built on the Java platform, and often require functionality not found in XQuery; for instance, many XML programs need to use the Web Services functionality of J2EE. On the Java platform, XML is accessed and manipulated as a DOM tree, a SAX stream, or as a StAX stream.
The XQuery API for Java, currently under development as JSR 225, lets programmers have the best of both worlds, using 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.
This article shows how XQJ is used to issue XQueries and obtain results. Next, it shows how XQJ can be used to query DOM trees, perform joins between XML and relational sources, obtain results using StAX, and issue prepared XQueries (similar to JDBC's prepared statements). Finally, we show four complete, working XQJ programs, including one that uses StAX to handle output. These programs are based on the Early Draft Review of JSR-225, released in May 2004. Code examples were tested with a pre-release version of DataDirect XQuery™, which implements XQuery and XQJ.