Changes

Jump to navigation Jump to search
144 bytes removed ,  18:37, 1 December 2023
m
Text replacement - "</syntaxhighlight>" to "</pre>"
import module namespace m = 'http://basex.org/modules/hello' at 'hello-world.xqm';
m:hello("Universe")
</syntaxhighlightpre>
'''Library Module''' <code>hello-world.xqm</code> (in the same directory):
'Hello ' || $world
};
</syntaxhighlightpre>
If no location is supplied, modules will be looked up in the repository. Repository modules are stored in the {{Code|repo}} directory, which resides in your [[Configuration#Home Directory|home directory]]. XQuery modules can be manually copied to the repository directory or installed and deleted via [[#Commands|commands]].
import module namespace functx = 'http://www.functx.com';
functx:capitalize-first('test')
</syntaxhighlightpre>
=Commands=
import module namespace m = 'http://basex.org/modules/Hello';
m:hello("Universe")
</syntaxhighlightpre>
==Java==
}
}
</syntaxhighlightpre>
Installation (the file will be copied to {{Code|org/basex/modules/Hello.jar}}):
import module namespace m = 'http://basex.org/modules/Hello';
m:hello("Universe")
</syntaxhighlightpre>
After having installed the module, all of the following URIs can be used in XQuery to import this module or call its functions (see [[Java Bindings#URI Rewriting|URI Rewriting]] for more information):
import module namespace m = 'http://basex.org/modules/Hello';
m:hello("Universe")
</syntaxhighlightpre>
; Wrapper Module {{Code|Hello.xqm}}:
java:hello($world)
};
</syntaxhighlightpre>
; Java class {{Code|Hello.java}}:
}
}
</syntaxhighlightpre>
If the JAR file is installed, {{Code|Combined}} will be displayed as type:
....
</package>
</syntaxhighlightpre>
* The jar file itself along with an XQuery file defining wrapper functions around the java methods has to reside in the module directory. The following example illustrates how java methods are wrapped with XQuery functions:
}
}
</syntaxhighlightpre>
We want to extend BaseX with this class and use its method. In order to make this possible we have to define an XQuery function which wraps the <code>print</code> method of our class. This can be done in the following way:
return p:print($printer, $str)
};
</syntaxhighlightpre>
As it can be seen, the class {{Code|Printer}} is declared with its binary name as a namespace prefixed with "java" and the XQuery function is implemented using the [http://docs.basex.org/wiki/Java_Bindings Java Bindings] offered by BaseX.
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu