Saxon is a command-line tool that you use to execute XQuery queries. Saxon is built as a Java application, so you'll need to have the Java runtime installed in order to run Saxon. You can download the Java runtime (J2SE) from http://java.sun.com/j2se/1.4.2/download.html
. After downloading and installing both Java and Saxon, it's important to set the Java CLASSPATH
environment variable before attempting to run Saxon. The purpose of this variable is to let Java know where all of the executable class files are located when it tries to run an application. In the case of Saxon, you're interested in letting Java know about the file saxon8.jar
, which is located in the main Saxon folder, usually \saxon
.
To set the CLASSPATH
variable for Saxon, just issue this command at the command line:
set classpath=%classpath%;\saxon\saxon8.jar
You may want to double-check the Saxon documentation for your specific version to make sure the .JAR
file has the same name as I've mentioned here (saxon8.jar
). If not, just change the code to match the file you have.
You're now ready to run Saxon but you need to know how to run it. However, before you get to that you need to understand how queries are stored for XQuery. XQuery documents are stored in files with a .XQ
file extension. In addition to the query code, all XQuery documents are required to start with the following line of code:
xquery version "1.0";
The query code then follows after this line. So you have an XQuery document with a .XQ
file extension and an XML file with probably a .XML
file extension, and you're ready to run the query on the XML document. Just issue the following command at the command line:
java net.sf.saxon.Query -s xmldoc.xml querydoc.xq > outdoc.xml
In this sample command, xmldoc.xml
is the XML source document, querydoc.xq
is the XQuery document, and outdoc.xml
is the output document that the query results are written to. There are numerous other options you can use with Saxon but this basic command is all you need to get going running your own queries.