Wednesday, December 05, 2007

Getting started with XProc using Eclipse

This post looks at how to get started with Norm Walsh's XProc implementation - using Eclipse.

XProc is an XML Pipeline Language, which is being defined by the folks at the XML Processing Model Working Group. Norm has an experimental implementation, hosted at https://xproc.dev.java.net/. The release notes are here.

Naturally enough, this is as a Netbeans project - but I thought I'd give it a try using Eclipse. It was pretty easy in the end:
  1. Start your favourite Eclipse version - I used 3.3
  2. Add in a Subversion plugin (since dev.java.net uses subversion). I've been using Subclipse lately. See http://subclipse.tigris.org/ for more details.
  3. Point your SVN explorer to the repository https://xproc.dev.java.net/svn/xproc
  4. Check out as a new Java Project using the Wizard.
  5. Download (some of) the required frameworks ... I found that I could get by with Saxon 6.5 and Saxon 9 to get started. Add these .jars to the build path. Also note that you should add saxon9-s9api.jar as well as saxon9.jar.
  6. Adjust the build path - so that these two directories are used as the java source:

    java/src
    java

    The second is required, since a number of configuration files are referenced using a path like /etc/configuration.xml and as such, they need to be findable on the classpath. Eclipse will make sure that you exclude java/src from this include. Your classpath should look something like this:


  7. I used the xproc.Driver class to do a simple test. It was not long before I realized that things were not happy due to my running on a Windows box. I needed to change this line:

    hash.put(port, "file://" + fn);

    to this:

    hash.put(port, "file://" + "/" + fn);

  8. I then needed to use this sort of command line arguments:

    -i source=c:\fred.xml java/samples/count.xpl

  9. This just runs the count pipeline against a simple xml document.
Simple.

Here's a screenshot of the project contents:




Note that some errors are shown (since not all required libraries are provided), and that all three of the saxon libs are required.

And for good measure, here's a screen shot of a successful run: