Database Reference
In-Depth Information
External
These are library modules written in XQuery. They follow the W3C XQuery
specification for library modules and allow users to easily write modules in
XQuery. For further information, see http://www.w3.org/TR/xquery/#dt-library-
module .
Internal
These are library modules written in Java. In these modules, the internals of
XQuery functions and variables are written in eXist's host programming lan‐
guage (Java) but are callable from XQuery as though they were any other XQuery
function or variable. This arguably follows the W3C XQuery specification for
library modules, but deviates slightly as eXist does not require you to explicitly
declare the functions as external functions in XQuery because it is able to per‐
form the required static type analysis regardless. For further information, see
http://www.w3.org/TR/xquery/#dt-external-function .
In this chapter we do not look at external modules, as they are not specific to eXist
and there is already a great wealth of material on them, both in this topic and other
XQuery learning resources. Instead, we focus here on internal modules and how you
can easily build your own using Java.
So perhaps first we should ask: why would we write a library module in Java as
opposed to XQuery?
There is really only one valid reason to consider:
It cannot be done in XQuery!
You'll need to turn to Java when it is impossible to solve your problem by putting
other XQuery functions together. You most likely want to introduce a new and
unique function. For example, W3C XQuery 1.0 has no functional capability for
sending email, so you may wish to create a function that allows this (in fact, such
an extension function is already included in eXist, as covered in mail ).
Conversely, there are many reasons why you should not write a library module in
Java as opposed to XQuery. Here are a few of the important ones:
Not understanding XQuery
It may be tempting to implement something in Java because you have not had as
much experience with XQuery. Generally speaking, this is a bad plan, as you will
be calling this Java from XQuery regardless—your time would most likely be bet‐
ter invested in learning more about XQuery. XQuery is really the thing that
makes eXist so powerful, so you would be well advised to get to grips with it.
Performance
When you write an XQuery function to implement a specific piece of business
logic or use case, it may call many other XQuery functions. Often people misun‐
Search WWH ::




Custom Search