Executing a simple XQuery

Executing XQuery in Java

In the XQJ API, there are 2 classes to execute XQueries against an XML Datasource, XQExpression and XQPreparedExpression. For the moment we will focus on executing an XQuery via XQExpression

Let's execute an XQuery which finds the title's of all of the books within the 'books.xml' document.

Save the following source file in the 'src' directory as SimpleQuery.java. Compile and execute it making sure that sxqj-beta1.jar is on the classpath.


import javax.xml.xquery.*; import net.cfoster.sedna.xqj.SednaXQDataSource; public class SimpleQuery { public static void main(String[] args) throws XQException { XQDataSource xqs = new SednaXQDataSource(); xqs.setProperty("serverName",