Database Reference
In-Depth Information
The textual description of our function.
Any expected parameters for our function. Our hello-world function does not
take any parameters, so we can use null here.
The return type and cardinality of our function. Our hello-world function will
return a single XML document node.
Any parameters that our functions expect will be passed into the eval function as
an array of Sequence objects.
As it is possible to encode more than one XQuery function in a single Java class
that extends BasicFunction , we switch on the name of the function that was
called from XQuery.
We call our business logic, which generates the “Hello World” XML document.
If we do not recognize which function was called, we throw an
org.exist.xquery.XPathException . This is really just for completeness and
should not ever be invoked, as eXist should not route unexpected XQuery func‐
tion calls to us.
We return the results of our processing to the XQuery.
This is our isolated business logic, which will generate our “Hello World” XML.
We use eXist's MemTreeBuilder to construct an XML document dynamically in
memory.
We define the namespace of the XML document that we are producing.
If you're constructing a custom XML document and there is
otherwise no defined namespace to use, it is considered good
practice to place the nodes of the document into the name‐
space of the module as opposed to the default namespace.
We return the XML document node of our constructed document.
Using the Hello World Module
As mentioned previously, the Java source code implementing the internal module
called exist.book.example.module.internal.HelloModule is supplied in the folder
Search WWH ::




Custom Search