I am probably missing something trivial here but I keep on getting


Exception in thread "main" net.sf.saxon.javax.xml.xquery.XQException: Java object cannot be converted to an XQuery value

        at net.sf.saxon.xqj.StandardDOMHandler.convertToItem(StandardDOMHandler.java:211)

        at net.sf.saxon.xqj.StandardDOMHandler.fromObject(StandardDOMHandler.java:56)

        at net.sf.saxon.xqj.SaxonXQDataFactory.createItemFromObject(SaxonXQDataFactory.java:280)

        at net.sf.saxon.xqj.SaxonXQDynamicContext.bindObject(SaxonXQDynamicContext.java:102)

        at foo.SaxonExtJavaObject.main(SaxonExtJavaObject.java:26)


Example code is


package foo;

import java.util.Properties;

import javax.xml.namespace.QName;

import net.sf.saxon.javax.xml.xquery.XQConnection;

import net.sf.saxon.javax.xml.xquery.XQException;

import net.sf.saxon.javax.xml.xquery.XQPreparedExpression;

import net.sf.saxon.javax.xml.xquery.XQResultSequence;

import net.sf.saxon.xqj.SaxonXQDataSource;


public class SaxonExtJavaObject {

  public String f() {

    return "Some string";


  public static void main(String[] args) throws XQException {

    SaxonXQDataSource xqds = new SaxonXQDataSource();

    XQConnection xqc = xqds.getConnection();

    String expr=

      "declare namespace sejo='java:foo.SaxonExtJavaObject'; " +

      "declare variable $user external; " +


    XQPreparedExpression e = xqc.prepareExpression(expr);

    e.bindObject(new QName("user"), new SaxonExtJavaObject(), null);

    XQResultSequence resSeq = e.executeQuery();

    System.out.println(resSeq.getSequenceAsString(new Properties()));




It’s unclear to me how I should bind the SaxonExtJavaObject.


All help greatly appreciated!







From: saxon-help-bounces@lists.sourceforge.net [mailto:saxon-help-bounces@lists.sourceforge.net] On Behalf Of Michael Kay
Sent: Tuesday, December 11, 2007 1:27 PM
To: 'Mailing list for SAXON XSLT queries'
Subject: Re: [saxon] XQuery XQJ and Java objects as external variables


Yes, you can use any of the bindXXX methods in the XQDynamicContext interface, which is implemented by XQExpression and XQPreparedExpression. For example


XQPreparedExpression exp = ...


exp.bindString(new QName("user"), "myusername", null);


Michael Kay



From: saxon-help-bounces@lists.sourceforge.net [mailto:saxon-help-bounces@lists.sourceforge.net] On Behalf Of Peter
Sent: 11 December 2007 12:00
To: saxon-help@lists.sourceforge.net
Subject: [saxon] XQuery XQJ and Java objects as external variables



I am trying to use XQJ to pass in a Java object as an external variable


E.g. this could be the query


declare namespace u="java:package.User";

declare variable $user external;



I have a way of doing this using Saxon’s “proprietary” API, but can this be done using XQJ?


Any guidance warmly welcomed,