Callbacks

SaxonCS offers a number of places where user-supplied code can be invoked to customize the required behaviour. Examples include:

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:

public class UuidInit : IProcessorInitializer { public void Initialize(Processor processor) { Console.WriteLine("UuidInit invoked for " + processor.ProductTitle); processor.SetProperty(Feature.TIMING, true); processor.RegisterExtensionFunction( new QName("http://example.com/ns", "uuid"), processor.ParseItemType("function() as xs:string"), args => new XdmAtomicValue(Guid.NewGuid().ToString())); } }

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.