CIS 97YT Index > Shell Files

CIS 97YT 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

wellformed.sh

#!/bin/sh
java -cp /usr/local/xmljar/xerces-2_0_0/xercesImpl.jar:\
/usr/local/xmljar/xerces-2_0_0/xmlParserAPIs.jar:\
/usr/local/xmljar/xerces-2_0_0/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_0_0/xercesImpl.jar:\
/usr/local/xmljar/xerces-2_0_0/xmlParserAPIs.jar:\
/usr/local/xmljar/xerces-2_0_0/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_3_0/bin/xml-apis.jar:\
/usr/local/xmljar/xalan-j_2_3_0/bin/xercesImpl.jar:\
/usr/local/xmljar/xalan-j_2_3_0/bin/xalan.jar \
org.apache.xalan.xslt.Process -IN $1 -XSL $2 -OUT $3 

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/xmljar/Fop-0.20.1/build/fop.jar:\
/usr/local/xmljar/Fop-0.20.1/lib/batik.jar:\
/usr/local/xmljar/Fop-0.20.1/lib/xalan-2.0.0.jar:\
/usr/local/xmljar/Fop-0.20.1/lib/xerces-1.2.3.jar:\
/usr/local/xmljar/Fop-0.20.1/lib/jimi-1.0.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