CIT041X Index > Shell Files

CIT041X Shell Files

You may copy and paste the following code into Linux shell files to make your work easier. Remember to make the files executable by using the chmod command. Example:

chmod u+x filename.sh

All of these shell files are written with the presumption that you have installed the xmljar directory in the /usr/local directory.

wellformed.sh

#!/bin/sh
java -cp /usr/local/xmljar/xerces-2_6_2/xercesImpl.jar:\
/usr/local/xmljar/xerces-2_6_2/xmlParserAPIs.jar:\
/usr/local/xmljar/xerces-2_6_2/xercesSamples.jar dom.Counter $1

To check to see if file testfile.xml is well-formed, you’d type this at the command prompt:

wellformed.sh testfile.xml

validate.sh (DTDs)

#!/bin/sh
java -cp /usr/local/xmljar/xerces-2_6_2/xercesImpl.jar:\
/usr/local/xmljar/xerces-2_6_2/xmlParserAPIs.jar:\
/usr/local/xmljar/xerces-2_6_2/xercesSamples.jar dom.Counter -v $1

To check to see if file testfile.xml is valid, you’d type this at the command prompt:

validate.sh testfile.xml

msvalidate.sh (Relax NG)

#!/bin/sh
java -jar /usr/local/xmljar/msv/msv.jar $1 $2

Note: If your XML document has an internal subset DTD, you may encounter errors of the form: Element type "mumble" must be declared. If so, use the following file instead. When you use this script, error messages will give line numbers and column numbers as before, but the column number will always be -1. That's why this is not the script I prefer to use.

#!/bin/sh
java -jar /usr/local/xmljar/msv/msv.jar -crimson $1 $2

To check to see if file testfile.xml is valid with respect to the Relax NG specified in file testfile.rng, you’d type this at the command prompt:

msvalidate.sh testfile.rng testfile.xml

transform.sh (XSLT)

#!/bin/sh
java -cp /usr/local/xmljar/xalan-j_2_6_0/bin/xml-apis.jar:\
/usr/local/xmljar/xalan-j_2_6_0/bin/xercesImpl.jar:\
/usr/local/xmljar/xalan-j_2_6_0/bin/xalan.jar:. \
org.apache.xalan.xslt.Process -IN $1 -XSL $2 -OUT $3 $4 $5 $6 $7 $8 $9

To transform a source file testfile.xml with the XSLT specified in file test_transform.xsl and place the output in file newfile.xml, you’d type this at the command prompt:

transform.sh testfile.xml test_transform.xsl newfile.xml

fop.sh (Formatting Objects to PDF)

#!/bin/sh
java -cp \
/usr/local/fop-0.20.5/build/fop.jar:\
/usr/local/fop-0.20.5/lib/batik.jar:\
/usr/local/fop-0.20.5/lib/xalan-2.4.1.jar:\
/usr/local/fop-0.20.5/lib/xercesImpl-2.2.1.jar:\
/usr/local/fop-0.20.5/lib/xml-apis.jar:\
/usr/local/fop-0.20.5/lib/jimi.jar:\
/usr/local/fop-0.20.5/lib/avalon-framework-cvs-20020806.jar \
org.apache.fop.apps.Fop $1 $2 $3 $4 $5 $6 $7 $8

To transform an XSL-Formatting Objects file testfile.fo to the PDF file testfile.pdf, you’d type this at the command prompt:

fop.sh testfile.fo testfile.pdf

To transform an XML file testfile.xml directly to PDF file testfile.pdf using transformation transform.xsl, you’d type this at the command prompt:

fop.sh -xml testfile.xml -xsl transform.xsl -pdf testfile.pdf