ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Storing an XML Document in Apache Xindice

by Deepak Vohra

Apache Xindice is a native XML database in which XML documents may be stored, queried, and modified. The advantage of a native database over a relational database is that mapping of XML to SQL is not required. Instead, XPath is used to query the Xindice database and XML:DB XUpdate is used to update the database. Xindice implements the Java XML:DB API to add, query, update XML documents to the Xindice database. XML documents in the Xindice database are stored in collections; a collection may consist of one or more XML documents. Xindice also provides a command-line tool which has the same functionality as the XML:DB API.

Preliminary Setup

The Xindice database is installed as a web application in a web server. To install the Xindice database, the Xindice API JAR files and the Xindice server web application are required.

  1. Download the Version 1.1b4 binary (JAR), xml-xindice-1.1b4-jar.zip, which has the Xindice XML:DB API JAR files.

  2. Download the Version 1.1b4 binary (webapp), xml-xindice-1.1b4-war.zip, which has the Xindice server web application.

  3. Extract xml-xindice-1.1b4-jar.zip to an installation directory, C:/xindice.

  4. Add the xerces-2.6.0.jar to the beginning of the CLASSPATH variable. Then add the following Xindice JAR files to CLASSPATH, where <Xindice> is the Xindice installation directory.

    Xindice JAR File Description
    <Xindice>/xindice-1.1b4/lib/xerces-2.6.0.jar Xerces XML parser
    <Xindice>/xindice-1.1b4/xindice-1.1b4.jar Core Server API
    <Xindice>/xindice-1.1b4/lib/commons-logging-1.0.3.jar Jakarta Commons Logging API
    <Xindice>/xindice-1.1b4/lib/xalan-2.5.2.jar XPath API
    • <Xindice>/xindice-1.1b4/lib/xmldb-api-20030701.jar
    • <Xindice>/xindice-1.1b4/lib/xmldb-api-sdk-20030701.jar
    • <Xindice>/xindice-1.1b4/lib/xmldb-common-20030701.jar
    • <Xindice>/xindice-1.1b4/lib/xmldb-xupdate-20040205.jar
    Implementations of XML:DB API and XUpdate API
    <Xindice>/xindice-1.1b4/lib/xmlrpc-1.1.jar XML-RPC API
    <Xindice>/xindice-1.1b4/lib/xml-apis.jar DOM API

    Table 1. Xindice JAR files

  5. Add <Xindice>/xindice-1.1b4/bin to the PATH variable.

  6. Add a XINDICE_HOME environment variable with the value <Xindice>/xindice-1.1b4.

  7. Extract xml-xindice-1.1b4-war.zip to an installation directory, C:/xindice.

  8. The Xindice web application is deployed in a web/application server (the WebLogic server 9.0 is used in this tutorial, though another web/application server may also be used). Install the WebLogic Server 9.0. Then create a WebLogic server domain with the WebLogic server Configuration Wizard. The default domain that gets created is base_domain.


The Xindice database may be accessed and modified with either the XML:DB and XUpdate APIs or the Xindice command-line tool. The XML:DB API includes the XpathQueryService service to query the database with XPath and the XUpdateQueryService service to update the database with XUpdate. The XML:DB/XUpdate APIs and the command-line tool are used to create an Xindice database collection, add XML documents to the database, retrieve XML documents from the database, query the database, and update the database. In each of the following sections, we shall first demonstrate the command-line tool and then the Xindice APIs.

The Xindice command-line tool is accessed with the xindice command. The syntax of the xindice command is:

xindice action [switch] [parameter]

Some of the xindice command action values are listed in Table 2.

Xindice Action Description
ac Adds a collection
dc Deletes a collection
ad Adds a document
dd Deletes a document
lc Lists the collections
rd Retrieves a document
ld Lists documents in a collection
xpath Queries a document with XPath
xupdate Updates a document with XUpdate

Table 2. Xindice command action values

Some of the xindice command switch values are listed in Table 3.

Xindice Switch Description
-c Specifies a collection context.The context syntax is of the form xmldb:xindice://host:port/db
-f Specifies a file path
-n Specifies a name
-q Specifies an XPath query

Table 3. Xindice command switch values

In the following sections refer to Table 2 and Table 3 for the Xindice action or switch used in the xindice command. As an example of the xindice command, list the collections in the Xindice database with the command:

xindice lc -c xmldb:xindice://localhost:7001/db

The result of the xindice command is:



Total collections: 2
XPath and XPointer

Related Reading

XPath and XPointer
Locating Content in XML Documents
By John E. Simpson

Pages: 1, 2, 3, 4, 5, 6

Next Pagearrow