A List Apart: for 
people who make websites

Using XML.

Setting up Linux XML Tools

Java ™

All the tools we will use in this article are written in Java, so you will need a Java Runtime Environment (JRE). You may obtain this at http://java.sun.com/j2se/1.4/download.html. You don’t need the Software Development Kit (SDK) unless you plan on writing Java programs of your own. Follow the instructions that come with the JRE and install it on your system.

Creating Directories

Create a directory named xmlapps in your home directory. This is where all the tools will go.

Create a directory named nutrition in your home directory. That is where you will save all the XML files from this article.

The Multi-Schema Validator

You may download the Multi-Schema Validator (MSV) from https://msv.dev.java.net/. Unzip the file into the xmlapps directory that you created above. It will create a directory which you may rename to msv (if it is not already named that).

Now create a file named msvalidate in your nutrition directory, and paste the following text into it:

#!/bin/sh
java -jar ${HOME}/xmlapps/msv/msv.jar $1 $2

Make sure you change the permissions to make the file executable: chmod 755 msvalidate. If your shell is anywhere other than /bin/sh, make the appropriate change.

Xalan

You may download Xalan, a tool which is used to transform XML from one form to another, at http://xml.apache.org/xalan-j/index.html

Again, you will unzip the file into the xmlapps directory. It will create a directory of the form xalan-j_2_x_y where the x and y are numbers that depend upon which version you have downloaded. To make our lives easier, just rename that directory to xalan-j

Now create a file named transform in your nutrition directory, and paste the following text into it.

#!/bin/sh
java -cp ${HOME}/xmlapps/xalan-j/bin/xml-apis.jar:\
${HOME}/xmlapps/xalan-j/bin/xercesImpl.jar:\
${HOME}/xmlapps/xalan-j/bin/xalan.jar \
org.apache.xalan.xslt.Process -IN $1 -XSL $2 -OUT $3 

Make sure you change the permissions to make the file executable: chmod 755 transform. If your shell is anywhere other than /bin/sh, make the appropriate change.

FOP

FOP is a tool that takes documents written in the XSL–FO (Extensible Stylesheet Language-Formatting Objects) markup language, and converts them to PDF files. You download it at http://xml.apache.org/fop/index.html. Again, you unzip it into the xmlapps directory. It will create a directory with a name like fop-0.20.3 (or whatever the current version number is). To make things easier, rename that directory to fop.

Now create a file named fop in your nutrition directory, and paste the following text into it. This is an adaptation of the shell file that comes with FOP, and it is specially tailored to the setup that we are describing here.

#!/bin/sh
#
# Shell script to run FOP, adapted from the Jakarta-Ant project.
# further adapted by JDEisenberg

FOP_HOME=${HOME}/xmlapps/fop

echo $FOP_HOME

if [ -n "$CLASSPATH" ] ; then
  LOCALCLASSPATH=$CLASSPATH
fi

# add fop.jar, which resides in $FOP_HOME/build
LOCALCLASSPATH=${FOP_HOME}/build/fop.jar:$LOCALCLASSPATH

# add in the dependency .jar files, which reside in $FOP_HOME/lib
DIRLIBS=${FOP_HOME}/lib/*.jar
for i in ${DIRLIBS}
do
    # if the directory is empty, then it will return the input string
    # this is stupid, so case for it
    if [ "$i" != "${DIRLIBS}" ] ; then
      if [ -z "$LOCALCLASSPATH" ] ; then
        LOCALCLASSPATH=$i
      else
        LOCALCLASSPATH="$i":$LOCALCLASSPATH
      fi
    fi
done

echo $LOCALCLASSPATH
java -classpath "$LOCALCLASSPATH" $FOP_OPTS org.apache.fop.apps.Fop "$@"

Make sure you change the permissions to make the file executable: chmod 755 fop. If your shell is anywhere other than /bin/sh, make the appropriate change.

Batik

Batik is a toolkit that lets you manipulate documents written in the Scalable Vector Graphics (SVG) markup language. You may download it at http://xml.apache.org/batik/. Be sure to get version 1.5 or greater (as of this writing, that is a beta version, but that’s OK).

Again, download it and unzip it into the xmlapps directory. Rename the directory that it creates to batik. Then, create a file named batik in the nutrition directory, and paste the following text into it.

#!/bin/sh
java -jar ${HOME}/xmlapps/batik/batik-svgbrowser.jar %1

Make sure you change the permissions to make the file executable: chmod 755 batik. If your shell is anywhere other than /bin/sh, make the appropriate change.