Main menu:

Site search

Feeds

Categories

August 2014
S M T W T F S
« Mar    
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Archive

running xquery as an ant task with eXist

Say you wanted to be able to pull info out of one xml document and plug it into another document using an ant task. Why, then it would be very handy to be able to run xquery from within ant. Luckily, eXist has published tools for doing just this. Eventually, I would like to get this working with non-exist xqueries, but for now here is how to get it working with eXist. There is documentation on the eXist website here, but it is incomplete and contains some errors. It is useful for knowing all the ant tasks that are available, though.

Make sure you have the eXist source files. If you installed the .jar version (I don’t think the .war version includes source) you should be good. Check to see if you have the file $EXIST/src/org/exist/ant/antlib.xml

Here is a build file that will create a database called test, and will perform a simple xquery (don’t forget to change the location of exist.home to whereever yours is installed):

<project xmlns:xdb=“http://exist-db.org/ant” basedir=“.” name=“Test project” default=“build” >

    <property name=“exist.home” location=“/Applications/eXist/” />
   
    <path id=“exist.classpath”>
        <fileset dir=“${exist.home}” includes=“*.jar”/>
        <fileset dir=“${exist.home}/lib” includes=“**/*.jar”/>
    </path>
    <typedef resource=“org/exist/ant/antlib.xml”
        uri=“http://exist-db.org/ant”>

        <classpath refid=“exist.classpath”/>
    </typedef>
   
    <target name=“props”>
        <echoproperties destfile=“properties”/>
    </target>

    <target name=“ant1″>
        <xdb:create uri=“xmldb:exist://localhost:8080/exist/xmlrpc/db/shakespeare/plays” collection=“test” user=“admin”
        />

    </target>
   
    <target name=“lovequery”>
        <loadfile property=“xquery” srcfile=“love.xq”/>
        <xdb :x query uri=“xmldb:exist://localhost:8080/exist/xmlrpc/db/shakespeare/plays” query=“${xquery}” outputproperty=“output”/>
        <echoproperties destfile=“output.properties”/>
    </target>
</project>

More to come as I make this more useful.

Comments

Comment from Kevin S. Clarke
Time: March 30, 2006, 4:24 pm

Very nice! Have you looked at Qexo (http://www.gnu.org/software/qexo/) as a way to do it without exist? It doesn’t have all the eXist specific XUpdate stuff (built into XQ now), but does standard XQuery processing.

Pingback from Solvitur ambulando » running xquery as an ant task with qexo
Time: June 8, 2011, 10:19 am

[...] to Kevin, who suggested I use Qexo to run xqueries in ant without having to use eXist. It [...]

Write a comment