Phil
Phil

Reputation: 41

Saxon .NET custom elements

I am using Saxon 8.9 in .NET and would like to create a custom element. The docs for this (admittedly old) version of Saxon are pretty vague around this feature and seem to suggest that it ether isn't possible at all or just not in .NET. Can anyone provide any more insight into whether this is possible?

UPDATE: Following the quick update from Michael I had another stab at this.

This results in the error XTDE1450 "Unknown extension element". I even tried getting the old sql extension java, converting to a dll using IKVM, but it also didn't work.

The documentation for newer versions discusses registering the namespace in the processor config, but the setExtensionElementNamespace doesn't exist in this old version. I am bound to 8.9 because that is the version our product uses and upgrading is not really viable.

I appreciate all the help.

Upvotes: 1

Views: 113

Answers (2)

Phil
Phil

Reputation: 41

The missing link here was how to get the classloader to resolve the ExtensionElementFactory.

The full name of the ExtensionElementFactory class in the namespace declaration needs an extra prefix of "cli." e.g. myBiz.saxon.extensions.customExtensionElementFactory would actually have the namespace of:

xmlns:myBiz="http://myBiz.com/extensions/cli.myBiz.saxon.extensions.customExtensionElementFactory"

When the factory is in a different referenced library you need to make sure that this lib has been loaded before the class loader tries to resolve it. This could be acheived using the GC.KeepAlive method as described here: IKVM ClassLoader or by invoking it through some other means. It's important to note that just having the library as a reference is not enough, it needs to have been 'loaded' for the ClassLoader to be able to resolve it.

Alternatively you can create a custom ClassLoader (implementing java.lang.ClassLoader) and register that with the processor:

processor.Implementation.setClassLoader(new customClassLoader());

Upvotes: 1

Michael Kay
Michael Kay

Reputation: 163587

By "custom element" I guess you mean an XSLT extension instruction (or extension element depending which version of the spec you're using).

The API for this hasn't changed much over the years, if I remember right, but it certainly seems odd to be doing new things with a release that old, let alone to expect help.

I don't recall ever testing that it was possible to achieve on .NET but it ought to be possible in theory. However, you'll need to put up with the fact that the interfaces are designed for Java rather than C#. The IKVM technology that Saxon on .NET uses makes it quite possible not only to call Java from C# and vice-versa, but also to implement a Java interface with a C# implementation, or to override Java methods with C# methods, and even to use the Visual Studio debugger on the mixed code base. So I can't say it will be easy but I'm reasonably confident that it should be possible.

Upvotes: 0

Related Questions