Storing an XML Document in Apache Xindiceby 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.
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.
Download the Version 1.1b4 binary (JAR), xml-xindice-1.1b4-jar.zip, which has the Xindice XML:DB API JAR files.
Download the Version 1.1b4 binary (webapp), xml-xindice-1.1b4-war.zip, which has the Xindice server web application.
Extract xml-xindice-1.1b4-jar.zip to an installation directory, C:/xindice.
Add the xerces-2.6.0.jar to the beginning of the
CLASSPATHvariable. Then add the following Xindice JAR files to
<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
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
Add <Xindice>/xindice-1.1b4/bin to the
XINDICE_HOMEenvironment variable with the value
Extract xml-xindice-1.1b4-war.zip to an installation directory, C:/xindice.
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
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
action values are listed in Table 2.
||Adds a collection|
||Deletes a collection|
||Adds a document|
||Deletes a document|
||Lists the collections|
||Retrieves a document|
||Lists documents in a collection|
||Queries a document with XPath|
||Updates a document with XUpdate|
Table 2. Xindice command action values
Some of the
switch values are listed in Table 3.
||Specifies a collection context.The context syntax is of the form
||Specifies a file path|
||Specifies a name|
||Specifies an XPath query|
Table 3. Xindice command switch values
In the following sections refer to Table 2 and Table 3 for the Xindice
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:
system meta Total collections: 2