SAXON - Calling external java functions in Xquery
Asked Answered
I

2

-3

I have a requirement to invoke java function in Xquery using Saxon processor.I came to know that saxon has various editions like HOME, PROFESSIONAL and ENTERPRISE.

I am looking for a open source edition which can help me to invoke external java functions in xquery.

Can somebody please help me with sample code?

Iives answered 7/5, 2015 at 10:39 Comment(0)
M
2

If you go back to Saxon 9.1 B you can do it in the open source version. Since 9.2 and the introduction of HE, PE and EE editions you need one of the comercial editions PE or EE to directly call into Java (Use reflexive extension functions). With HE you can implement integrated extension functions http://saxonica.com/html/documentation/extensibility/integratedfunctions/.

Mock answered 7/5, 2015 at 10:57 Comment(4)
Thanks for the response Martin. Can you please publish sample code if you have. That will be much helpful to me.Iives
The documentation I linked to has examples like saxonica.com/html/documentation/extensibility/… and saxonica.com/html/documentation/extensibility/…. And a simple example calling a reflexive extension function also taken from the documentation is: declare namespace math="java:java.lang.Math"; for $d in (4, 9, 16, 25) return math:sqrt($d).Mock
I tried it and its working but im looking for code which uses saxon 9.1B to invoke external methods..Iives
That example declare namespace math="java:java.lang.Math"; for $d in (4, 9, 16, 25) return math:sqrt($d) should work with Saxon 9.1 B I think and you can then access other classes with the same mechanism. Also the Saxon 9.1 B documentation and sample files you can download from saxon.sourceforge.net (sourceforge.net/projects/saxon/files/Saxon-B/9.1.0.8/…) should have more details.Mock
A
1

You can call Java extension functions in all editions of Saxon.

With the open source edition (Saxon HE), you can only use the mechanism where you have to write an extension function class in Java, implementing some abstract classes from Saxon, and configuring Saxon with those.

With the other editions, you can also use the introspection mechanism, where you use a namespace with a specific format, which will look for an implementation matching the function QName in the classpath.

For a more robust approach, which also let you all freedom in choosing the namespace (not tidying it to any implementation detail), I recommend the first one above.

Angelinaangeline answered 8/5, 2015 at 12:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.