CodeKiller
CodeKiller

Reputation: 107

SAXON - XPST0017: Cannot find a matching 1-argument function named

I have a simple jar test program which I use to parse xml with xquery file. Problem is that in the xquery file I declare a java namespace :

declare namespace java="java:MyString";

Then for testing purpose I just have a static method toString(Object o).

When I execute it outside of Eclipse (who managed the classpath correctly when I set a class folder manually) I get the error in the title :

> C:\>java -jar XQueryJava.jar
> -xq XQuery\test.xq -xml XQuery\test.xml Error on line 9 of XQuery\test.xml:   XPST0017: Cannot find a matching 1-argument
> function named {java:MyString}toString() ; SystemID: XQuery\test.xml;
> Line#: 9; Column#: -1 net.sf.saxon.trans.StaticError: Cannot find a
> matching 1-argument function named {java:MyString}toString()
>         at net.sf.saxon.query.UnboundFunctionLibrary.bindUnboundFunctionCalls(UnboundFunctionLibrary.java:114)
>         at net.sf.saxon.query.StaticQueryContext.bindUnboundFunctionCalls(StaticQueryContext.java:1479)
>         at net.sf.saxon.query.QueryParser.makeXQueryExpression(QueryParser.java:106)
>         at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:472)
>         at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:502)
>         at xpath.AffichageXPath.execute(AffichageXPath.java:91)
>         at xpath.AffichageXPath.main(AffichageXPath.java:49)

I tried to use "-cp" and the folder I put the .class file in :

java --class-path XQuery\class -jar XQueryJava.jar -xq XQuery\test.xq -xml XQuery\test.xml

But still same issue.

If I put the class file in the same folder as the jar everything is fine. Why is it not working with the CP argument ? I thought it was the point of it...

Any idea ?

Thanks.

Upvotes: 0

Views: 3421

Answers (1)

Michael Kay
Michael Kay

Reputation: 163342

First the stack trace shows that you are invoking the processor with

net.sf.saxon.query.StaticQueryContext.compileQuery

which is a pretty low-level entry point, and there are many ways of getting things wrong at this level. I would recommend you use the s9api interface (XQueryCompiler.compile()).

One of the things you can easily get wrong is to run without Saxon-PE/EE enabled. Calls to reflexive extension functions require at least Saxon-PE, which also needs a license file to be present. Check that the Saxon Configuration is a ProfessionalConfiguration or an EnterpriseConfiguration.

Using the -TJ option on the command line, or the equivalent configuration property in the API (FeatureKeys.TRACE_EXTERNAL_FUNCTIONS) will give you better diagnostics as to why it is failing to find the function.

Finally, note that using -jar on the Java command line means that the class path is ignored: everything has to be loaded from the JAR file itself. This makes it quite difficult to pick up the license file and any external library classes, so it is best avoided.

Upvotes: 1

Related Questions