Database Reference
In-Depth Information
chapters/advanced-topics/internal-module/hello-world-module-example of the book-
code Git repository (see “Getting the Source Code” on page 15 ). The example covers
both the simple hello-world function just discussed and a more complex say-hello
function, which is described next. It is designed to show how relatively little bespoke
code is required to implement a simple internal module.
To compile the example, enter the internal-module folder and run mvn package .
To deploy the HelloModule to eXist, you need to:
1. Compile the code as previously described, and then copy all of the files from
internal-module/hello-world-module-example/target/hello-world-module-
example-1.0-assembly to $EXIST_HOME/lib/user .
2. Add the following module definition to $EXIST_HOME/conf.xml , in the xquery/
builtin-modules section:
<module uri= "http://hello"
class= "exist.book.example.module.internal.HelloModule" />
3. Restart eXist so that it picks up the new JAR files.
To test the example:
1. Execute the following XQuery from either eXist's Java Admin Client (see “Java
Admin Client” on page 373 ) or eXide (see “eXide” on page 374 ):
xquery version "1.0" ;
declare namespace h = "http://hello" ;
h:hello-world ()
2. You should see a result that looks similar to:
<h:hello xmlns:h= "http://hello" > world </h:hello>
While this example shows you how to write an extension function for XQuery in
Java, it is very basic. To expand on this, we will look next at eXist's Java model of the
XDM types used in XQuery, and then study an example where we create a function
that takes several parameters using these types and acts upon them.
Types and Cardinality
Where functions take arguments and return values as a result of their computation
(and they should in the functional world), these arguments and return values have
both a type and a cardinality . The type defines the variety of data that can be held (for
example, a string or number), and the cardinality defines how many values of that
type may be present. Types and cardinalities are defined in the W3C XQuery 1.0 and
Search WWH ::




Custom Search