Table of Contents
If you do not know, what SGML/XML catalogs are good for and if you really need them, read excellent article If You Can Name It, You Can Claim It! from Norman Walsh. Norman developed set of Java classes, which implements catalog mapping. Syntax of catalog files is described in OASIS Technical Resolution 9401:1997 (Amendment 2 to TR 9401). This page describes how to extend popular XSLT processor Saxon to support catalogs.
Saxon allows you to replace parser used to read XML files and XSLT stylesheets. Usually you need catalogs only for input XML files. To use Saxon with catalog files do following steps:
Install Saxon from above mentioned address. Use pure Java version, not Instant Saxon.
Download Java archive kosek.jar with catalog support and save it somewhere on your drive.
Download Crimson parser. Crimson is a part of JAXP package from Sun, also can be downloaded separately from Crimson pages. You need file named crimson.jar. For your convenience I placed copy of this file at my site.
Now you can run Saxon by following command:
java -cp /path/to/crimson.jar;/path/to/kosek.jar;/path/to/saxon.jar -Dxml.catalog.files=your_catalog_files com.icl.saxon.StyleSheet -x cz.kosek.CatalogXMLReader normal saxon parameters
Off course, command should not be split across several lines as on your screen.
If you use Saxon on regular basis, you probably want to make some batch file or shell script to invoke it. If you have already path to your catalogs stored in environment variable SGML_CATALOG_FILES create something like saxon.bat on Windows:
@java -cp /path/to/crimson.jar;/path/to/kosek.jar;/path/to/saxon.jar -Dxml.catalog.files=%SGML_CATALOG_FILES% com.icl.saxon.StyleSheet -x cz.kosek.CatalogXMLReader %1 %2 %3 %4 %5 %6 %7 %8 %9
Or if you are happy unix user:
#!/bin/sh @java -cp /path/to/crimson.jar;/path/to/kosek.jar;/path/to/saxon.jar -Dxml.catalog.files=$SGML_CATALOG_FILES com.icl.saxon.StyleSheet -x cz.kosek.CatalogXMLReader $*
Saxon is able to use user supplied parser to read XML files. This parser must implement XMLReader interface from SAX2. My solution to catalog classes uses existing implementation of this interface by Crimson. I created descendant of Crimson XMLReader class in which I changed entity resolver to resolver implemented by Java Catalog Classes.
Whole magic thing is one simple class named CatalogXMLReader.java. In order to build it, you must have Crimson parser and above mentioned Java Catalog Classes.
If you find some bug in program or you have found way how to improve it, please feel free to contact me by e-mail <jirka@kosek.cz>.