Java Examples

From BaseX Documentation
Jump to navigation Jump to search

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[edit]

The following code snippets work in embedded mode; they do not rely on an additional server instance:

Server Examples[edit]

The examples below take advantage of the client/server architecture:

XQuery Module Examples[edit]

BaseX provides Java Bindings for accessing external Java code via XQuery functions. The following examples show how this feature can be utilized:

  • FruitsExample.java
    demonstrates how Java classes can be imported as XQuery modules.
  • FruitsModule.java
    is a simple demo module called by FruitsExample.
  • ModuleDemo.java
    is a simple XQuery demo module that demonstrates how XQuery items can be processed from Java. It is derived from the QueryModule class.
  • QueryModule.java
    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 ().
 

Client API[edit]

REST API[edit]

XML:DB API (deprecated)[edit]

Note that the XML:DB API does not talk to the server and can thus only be used in embedded mode.

XQJ API (closed source)[edit]

The implementation of the BaseX XQJ API has been written by Charles Foster. The basex-examples repository contains various examples on how to use XQJ.