Declaring External Functions

External functions can be provided by a particular XQuery implementation. They may be unique to that implementation or be part of a standard set of extensions defined by a user community. They may be implemented in XQuery or in another language; they simply need to be able to interface with a query using an XQuery function signature.

External functions may be declared with signatures in the query prolog. Their syntax starts out similar to a function declaration, but instead of a function body in curly braces, they use the keyword external. For example:

declare function ext:trim ($arg as xs:string?) as xs:string? external;

declares an external function named trim. Like other function names, the names of external functions must be prefixed. This example assumes that the ext prefix has been declared using a namespace declaration.

Note that external functions are not the same thing as user-defined functions that are imported from other modules. Functions declared in imported modules do not need to be redeclared in the importing module.

You should consult the documentation for your XQuery implementation to determine whether there are libraries of external functions that you can call, or whether you are able to write external functions of your own. Many processors are likely to provide the capability to write external functions written in procedural programming languages such as C# and Java. This creates the possibility of calling functions that have side effects. Even fairly innocent-looking functions, such as reading a record from a file, can have side effects (in this case, it changes the current position in the file). Such functions need great care because XQuery does not define the order of evaluation, and in some cases it may not call a function at all if the results aren't needed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.239.118