N. America: 800 876 3101 | World: 44 (0) 1753 218 930

Overview: The XQueryWebService Framework

XQueryWebService is a framework that allows you to expose an XQuery as a Web service. In this section, you'll see how you can use DataDirect XQuery to build powerful data services that query, aggregate, and update multiple data sources using XQuery.


About the Example

The application used to illustrate some of the features of the XQueryWebService framework is a simple employee lookup: based on the employee ID you enter, the query returns information such as first and last name, job level, date of hire, and so on.

Before You Begin

Before getting started with the example presented in this section, you'll need the following:

  • A copy of DataDirect XQuery — If you don't already have DataDirect XQuery installed, you can download an evaluation version here: http://www.xquery.com/download/.
  • Note: You need to use at least DataDirect XQuery 3.1 (build 034703). If you already have installed DataDirect XQuery but are using an earlier build, you can either:


  • An XQuery editor — You will need an XQuery editor to author the XQuery you wish to expose as a Web service. You can use any XQuery editor you like, but we're partial to DataDirect's Stylus Studio and the DataDirect XQuery Editor for Eclipse.

  • A Java servlet container — The XQueryWebService framework has been tested with several Java servlet containers, including:
  • You can use any Java servlet container you like; we used the open source Apache Tomcat for this example, so you will have to adjust references to Tomcat to the Java servlet container of your choice in your installation.

Getting Started

To get started with the XQueryWebService example:

  1. Download the xquerywebservice.jar file.
  2. Copy the DataDirect XQuery libraries to the Java servlet container \lib folder (<Tomcat_dir>\lib, for example).
  3. Create an employee-lookup folder under the Java servlet container \webapps folder (<Tomcat_dir>\webapps\employee-lookup, for example).
  4. Create a WEB-INF folder under the newly created \employee-lookup folder (<Tomcat_dir>\webapps\employee-lookup\WEB-INF, for example).
  5. Place the following configuration file, web.xml, in the WEB-INF folder:

  6. <?xml version="1.0"?>
    <web-app
    xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi=
    "http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation=
    "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version=
    "2.4">

        <description>Employee lookup</description>
        <display-name>Employee-lookup</display-name>

        <servlet>
            <servlet-name>XQueryWebService</servlet-name>
            <servlet-class>com.ddtek.xquery.webservice.XQServlet</servlet-class>
            <init-param>
                <param-name>JNDIDataSourceName</param-name>
                <param-value>jdbc/employee-lookup</param-value>
            </init-param>
       <init-param>
                <param-name>QueriesFolder</param-name>
                <param-value>c:\MyQueryDir</param-value>
           </init-param>
        </servlet>

        <resource-ref>
            <res-ref-name>jdbc/employee-lookup</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
        </resource-ref>

        <servlet-mapping>
            <servlet-name>XQueryWebService</servlet-name>
            <url-pattern>/*</url-pattern>
        </servlet-mapping>
    </web-app>


    What's Next?

    Once you've taken care of the basics, you're ready to move on, starting with specifying relational data sources, as described in the following section.

XQJ Tutorial!

Learn about the power of DataDirect XQuery and XQJ now!

This informative tutorial covers basics and advanced concepts in quick, easy-to-read chapters, and includes four working code samples to help you learn.

Try DataDirect XQuery for Free!

Put the power, scalability, and performance of DataDirect XQuery to work for you today! Our free trial lets you see for yourself how easy it is to build data integration applications that access relational, EDI, and other file formats as XML!

Download DataDirect XQuery today!