Callbacks
SaxonCS offers a number of places where user-supplied code can be invoked to customize the required behaviour. Examples include:
The ErrorReporter, used to report errors and warnings
The ResourceResolver, used to resolve URI references to external resources
The IInvalidityHandler, used to report on validation errors found during schema processing
The Extension functions (C#) interfaces used to implement C# functions that can be invoked from XPath expressions
Generally the application registers these callback types with the Saxon Processor. This means that no dynamic loading of user-written code is required.
The one exception is where a query, transformation, or schema validation is run using the command-line interface.
In this scenario, a user-written initialization hook can be nominated by name, in the -init
option. The value of the
option is a (relative) filename, which must refer to a DLL containing a class that implements the interface
Saxon.Api.IProcessorInitializer.
Here is an example of an initialization class. It switches the configuration option Feature.TIMING
on,
and declares an extension function:
To invoke this initializer, specify -init:uuid.dll
on the command line, where uuid.dll
is the location of the compiled project.
Within this Saxon configuration, the extension function Q{http://example.com/ns}uuid()
can then
be called to generate a UUID.
The initializer should be used only to set properties of the Saxon Processor
; it should not be used
to do significant work such as running queries or transformations.