You might want to look at the xmlsh ant interface.

It is based on saxon for all the XML processing but uses the saxon internal API's so it doesnt have the feaure

of exiting on error.   It also can do prety much everything xproc can do but you wont have to leave ant.

Actually with xmlsh you dont need ant but as you mentioned you dont want to rewrite everything.

 

http://www.xmlsh.org/AntTask

 

 

 

 

 

----------------------------------------

David A. Lee

dlee@calldei.com

http://www.xmlsh.org

 

From: Tom Cleghorn [mailto:tcleghorn@cambridge.org]
Sent: Friday, March 09, 2012 5:01 AM
To: Mailing list for the SAXON XSLT and XQuery processor
Subject: Re: [saxon] Saxon Xquery in Ant

 

XProc is firmly on the radar, but unfortunately we've a skipload of these Ant builds - I can just about find the time to improve some of the existing ones, but I haven't a hope of having the time to rebuild any from the ground up. The same pretty much applies to the idea of a new wrapper, of course.

I'll look closer into my query - as you can probably tell, the aim was to get the quickest and dirtiest approach that'd still give me the right result, and in light of the comments about dynamic errors, I'm wondering if Ant is mangling the -qs argument somehow, though I'm still puzzled as to why it doesn't return 2 when I use fork=true. Perhaps using a proper query in an external file would help?



From:        Michael Kay <mike@saxonica.com>
To:        saxon-help@lists.sourceforge.net
Date:        08/03/2012 14:40
Subject:        Re: [saxon] Saxon Xquery in Ant





The Saxon command line interfaces typically do a System.exit(2) if a query/transformation fails with a dynamic error; this is so that shell scripts can detect whether or not the command was successful. There is no System.exit() call if execution succeeds.

I don't think anyone is especially at fault here. You're using an interface that's designed to be called from a shell script from within a Java application, which is best avoided, but Ant doesn't give you very much alternative. If you really want to make the effort, the right answer is probably to write a different wrapper around the Query API, similar to net.sf.saxon.Query, but with a different strategy for reporting success or failure to the calling application. Alternatively, write the query to be more robust, so it doesn't fail with dynamic errors: I don't think there should be a problem for successful queries.

Another alternative: perhaps you should be using XProc?

Michael Kay
Saxonica

On 08/03/2012 12:09, Tom Cleghorn wrote:
Hi,

I've got an Ant build in which I use the "java" task to pull a couple of values from an XML document and store them in properties for use later in the build.


Currently, the tasks look like this:


<java classname="net.sf.saxon.Query" outputproperty="oc-isbn" fork="true">

 <classpath>

   <pathelement location="${basedir}/lib/saxon9.jar"/>

 </classpath>

 <arg value="-qs:doc('${xml-meta}')//book[HB_ISBN='${isbn}']/OC_EAN[1] | doc('${xml-meta}')//book[PB_ISBN='${isbn}']/OC_EAN[1]"/>

 <arg value="!method=text"/>

</java>


...and this works. However, I have other builds where setting the result of an Xquery to a property would also be useful, but where I have quite a few more properties to set. So, what I'd really like to do is be able to use 'fork="false"', so that I don't have to wait for a new VM to start up for each property, but this does not work. If I do this, I get "Java Result: 2" from Ant, and the properties remain unset.


I played around a bit, and found that Saxon was complaining about Java security permissions, and that led to finding that, if I specifically granted Saxon all permissions, it would run without error, but then end the build prematurely - with some further fiddling, I found that granting Saxon all permissions *except* ExitVM would give me Java Result: 2 again. So it looks as if Saxon really wants to close the VM when it finishes, but with fork=false, this is the VM in which Ant is running - is this the right conclusion? I'm using Ant 1.8.1, Saxon-B 9.1 and Java 1.6, but I've also tried with Ant 1.7.0, 1.7.1 and 1.8.1, and Saxon HE 9.3 and 9.4.


I'm really running up against the boundaries of my understanding of Java here, so I'm honestly unsure if I'm doing something daft, and even if I'm not, whether it's Saxon, Ant, or Java itself that's causing the problem. Can anyone shed any light?


Many thanks!


------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/


_______________________________________________
saxon-help mailing list archived at
http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help ------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/_______________________________________________
saxon-help mailing list archived at
http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help