Skip to Content
XQuery
book

XQuery

by Priscilla Walmsley
March 2007
Intermediate to advanced content levelIntermediate to advanced
512 pages
21h 15m
English
O'Reilly Media, Inc.
Content preview from XQuery

XQuery API for Java (XQJ)

XQJ is a standard for calling XQuery from Java. XQJ is to XML data sources what JDBC is to relational data sources. It provides a standard set of classes for connecting to a data source, executing a query, and traversing through the result set. It is being developed using the Java Community Process as JSR 225 and is currently in the Early Draft Review 2 stage.

Example 22-4 shows an example of Java code that connects to an XML data source and iterates through the results.

Example 22-4. XQJ example

// connect to the data source
XQConnection conn = xqds.getConnection( );

// create a new expression object
XQExpression expr = conn.createExpression( );

// execute the query
XQResultSequence result = expr.executeQuery(
    "for $prod in doc('catalog.xml')//product" +
    "order by $prod/number" +
    "return $prod/name");

// iterate through the result sequence
while (result.next( )) {

    // retrieve the atomic value of the current item
    String prodName = result.getAtomicValue( );
    System.out.println("Product name: " + prodName);
}

For more information on XQJ, see the specification at http://jcp.org/en/jsr/detail?id=225.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

XQuery, 2nd Edition

XQuery, 2nd Edition

Priscilla Walmsley
XPath and XPointer

XPath and XPointer

John Simpson
XQuery Kick Start

XQuery Kick Start

James McGovern, Per Bothner, Kurt Cagle, James Linn, Vaidyanathan Nagarajan
Learning XSLT

Learning XSLT

Michael Fitzgerald

Publisher Resources

ISBN: 0596006349Supplemental ContentErrata