Project

Profile

Help

Call to Java function from XQuery

Added by Anonymous about 17 years ago

Legacy ID: #4224234 Legacy Poster: popol (mrjeje)

Hello everyone, I'm currently experimenting a problem while executing an external Java function from an XQuery. My query: declare namespace mine="java:Test"; let $a:=mine:test(null) return $a where 'mine' is a declared namespace for the 'Test' class having one 'test' method taking a string as parameter. So in the upper example, I pass 'null' as parameter and got the following exception as a result : Error on line 1 of module with no systemId: XPDY0002: Error in call to extension function {public static java.lang.String Test.test(java.lang.String)}: The context item is not set Exception in thread "main" ; SystemID: module with no systemId; Line#: 1; Column#: -1 net.sf.saxon.trans.DynamicError: Error in call to extension function {public static java.lang.String Test.test(java.lang.String)}: The context item is not set at net.sf.saxon.functions.ExtensionFunctionCall.iterate(ExtensionFunctionCall.java:118) at net.sf.saxon.expr.ComputedExpression.evaluateItem(ComputedExpression.java:564) at net.sf.saxon.expr.ExpressionTool.evaluate(ExpressionTool.java:360) at net.sf.saxon.expr.LetExpression.eval(LetExpression.java:182) at net.sf.saxon.expr.LetExpression.iterate(LetExpression.java:163) at net.sf.saxon.query.XQueryExpression.iterator(XQueryExpression.java:239) at net.sf.saxon.query.XQueryExpression.evaluate(XQueryExpression.java:156) Of course, when I pass an empty string as parameter, everything works well but my point is that in my program I have to call external Java method taking up to seven parameters with at least 5 of them that can be null. I would like to avoid writing the same function several times with different parameters. So my question : Can the 'null' be used as parameter of external function calls? If so I may be doing something wrong in the query. Thanks in advance, Jérôme.


Replies (2)

RE: Call to Java function from XQuery - Added by Anonymous about 17 years ago

Legacy ID: #4224416 Legacy Poster: Michael Kay (mhkay)

You would get the same error if you wrote your query as let $a:=string(null) return $a null is an axis step looking for a child element of the context node called "null". You can't use an axis step when there is no context node. Try passing the empty sequence () - I'm not 100% sure without checking my facts, but I think it should work. Michael Kay http://www.saxonica.com/

RE: Call to Java function from XQuery - Added by Anonymous about 17 years ago

Legacy ID: #4227488 Legacy Poster: popol (mrjeje)

Hello, It works using the empty sequence '()'. Thanks a lot. Jérôme.

    (1-2/2)

    Please register to reply