What is the text of your query, that is, the contents of c:\dev\ftp\data\filter.xq? In particular, does it call the doc() function?
 
A problem with passing a FileInputStream to Saxon is that Saxon doesn't know which file it is reading from, therefore the associated query or XML document has no usable base URI. In such cases Saxon interprets relative URIs as being relative to the current directory. It's always better to establish an explicit base URI. For an XML document you can do this using the third argument of bindDocument() (which you have set to null); for the query, you can do it by passing an XQStaticContext (on which you have first called setBaseURI()) as the second argument of prepareExpression(). This should only matter if your query contains a call to doc('feed.xml') - but my guess is that it does.
 
Incidentally, the whole point of the XQJ interface is that it's a standard API that should work with multiple XQuery implementations. So your application should be using the interface names (XQDataSource), not the Saxon implementation class names (SaxonXQDataSource). If you're going to call Saxon-specific interfaces, I would suggest using the s9api interface instead as it's a much better fit to Saxon's overall architecture.
 
Michael Kay
Saxonica


From: sldahlin [mailto:sldahlin@zoho.com]
Sent: 14 October 2008 16:19
To: saxon-help@lists.sourceforge.net
Subject: [saxon] java.io.FileNotFoundException in SaxonXQPreparedExpression.executeQuery()

I am getting a FileNotFoundException when trying to execute query for a prepared expression.  The core code looks like the following:

SaxonXQDataSource ds              = new SaxonXQDataSource();
SaxonXQConnection conn            = (SaxonXQConnection) ds.getConnection();
java.util.Properties prop            = new Properties();
   
prop.setProperty( "method", "xml" );
prop.setProperty( "indent", "yes" );
           
File filDoc          = new File( "C:\\dev\\ftp\\data\\feed.xml" );
File filXqj          = new File( "C:\\dev\\ftp\\data\\filter.xq" );
           
FileInputStream  fisDoc          = new FileInputStream( filDoc );
FileInputStream fisXqj          = new FileInputStream( filXqj );
           
SaxonXQPreparedExpression exp             = (SaxonXQPreparedExpression) conn.prepareExpression( fisXqj );
           
exp.bindDocument( XQConstants.CONTEXT_ITEM,
                              (InputStream) fisDoc,
                              null,
                              null );
                             
xqResult        = exp.executeQuery();

When it runs the executeQuery() it errors with the exception indicating that it cannot find the xml file: "C:\\dev\\ftp\\feed.xml"!  Somehow it wants to find the feed.xml in the parent directory of where it actually is.  I should mention that I think the java app is actually executed from the "C:\\dev\\ftp" directory but I made sure that the File object does indeed point to C:\\dev\\ftp\\data\\feed.xml" and that the FileInputStream object can read which is the case up until I execute the bindDocument() function with the expression.  After the bindDocument() is executed that is when the error occurs.

Steve