From BaseX Documentation
This page is part of the Developer Section. The following Java code snippets demonstrate how easy it is to run database commands, create collections, perform queries, etc. by integrating the BaseX code. Most examples are taken from our basex-examples repository, in which you will find some more use cases.
 Local Examples
The following code snippets work in embedded mode; they do not rely on an additional server instance:
creates and drops database and index instances, prints a list of all existing databases.
shows three variants of running queries.
demonstrates how a value can be bound as context item.
demonstrates how a value can be bound to a variable.
creates and manages a collection.
creates, runs queries against it and drops a collection.
creates a database from an url (wiki instance), runs a query against it and drops the database.
 Server Examples
The examples below take advantage of the client/server architecture:
launches server-side commands using a client session.
processes server results locally.
runs concurrent queries.
shows how iterative queries can be performed.
is a little GUI example for demonstrating database events.
manages database users.
 XQuery Module Examples
BaseX provides Java Bindings for accessing external Java code via XQuery functions. The following examples show how this feature can be utilized:
demonstrates how Java classes can be imported as XQuery modules.
is a simple demo module called by
is a simple XQuery demo module that demonstrates how XQuery items can be processed from Java. It is derived from the
is located in the BaseX core. Java query modules can extend this class to get access to the current query context and enrich functions with properties ().
 XQJ API
The implementation of the BaseX XQJ API (closed-source) has been written by Charles Foster. It uses the client/server architecture. The basex-examples repository contains various examples on how to use XQJ.
provides an implementation of the Server Protocol.
demonstrates how commands can be executed on a server.
shows how queries can be executed in an iterative manner.
shows how external variables can be bound to XQuery expressions.
shows how new databases can be created.
shows how documents can be added to databases, and how existing documents can be replaced.
demonstrates how to trigger and receive database events.
shows how binary resource can be added to and retrieved from the database.
presents the HTTP GET method.
presents the HTTP POST method.
presents the HTTP PUT method.
runs all examples at one go.
 XML:DB API (deprecated)
Note that the XML:DB API does not talk to the server and can thus only be used in embedded mode.