Monday 8 October 2012

How to run an XQuery script


First, for the XQuery processor (the one that I use in the following steps) to work you need to have Java installed.

1) Download an XQuery processor for Java. I used Saxon. If you don't have material resources (like myself) download the home edition. You'll need to pay for the commercial ones if you choose to use one. When I wrote this article I downloaded SaxonHE9-4-0-6J.zip from the following link:

http://sourceforge.net/projects/saxon/files/Saxon-HE/9.4/

2) Extract the zip file to a path you can remember. It will result in 2 jar files:
3) Run your XQuery script by adding the extracted saxon9he.jar file to your java classpath:

java -classpath C:\.....\saxon9he.jar net.sf.saxon.Query my.xquery

where my.xquery is your xquery script, e.g.


<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:bibterms="http://www.book-stuff.com/terms/">

    <rdf:Description rdf:about="http://www.book-stuff.com/bib">
    {
        for $book in doc( "bib.xml" )//book
        return 
            <bibterms:book rdf:parseType="Resource">
            </bibterms:book>
    }
    </rdf:Description>

</rdf:RDF>

This command will output the resulting RDF file on the console. If you prefer having the result in a file, just add > filename.ext to the command, e.g:


java -classpath C:\.....\saxon9he.jar net.sf.saxon.Query my.xquery > result.rdf


No comments:

Post a Comment