I downloaded SaxonHE9-4-0-6J and want to process XHTML on CLI. However Saxon tries to load DTD from W3C and it takes too much time for every simple command.
I have xml catalog, which I use successfully with xmllint by set env variable pointing to catalog file, but I have no idea how to make Saxon use it. Google reveals whole history of changes (thus confusion) in regards of using catalogs with Saxon, and none made me happy.
I downloaded resolver.jar and set it in my CLASSPATH, but I can't make Saxon use it. After various combinations, I followed http://www.saxonica.com/documentation/sourcedocs/xml-catalogs.xml by using just catalog variable, like:
-catalog:path-to-my-catalog
(tried both URI and regular paths), and without setting -r
, -x
, -y
switches, but Saxon doesn't see it. I get this error:
Query processing failed: Failed to load Apache catalog resolver library
resolver.jar is set in my classpath and I can use it from command line:
C:\temp>java org.apache.xml.resolver.apps.resolver
Usage: resolver [options] keyword
Where:
-c catalogfile Loads a particular catalog file.
-n name Sets the name.
-p publicId Sets the public identifier.
-s systemId Sets the system identifier.
-a Makes the system URI absolute before resolution
-u uri Sets the URI.
-d integer Set the debug level.
keyword Identifies the type of resolution to perform:
doctype, document, entity, notation, public, system,
or uri.
OTOH, Saxon archive itself already includes XHTML and various other DTDs, so there must be simple way out from this frustration.
How to use Saxon on command-line and instruct it to use local DTDs?
Daniel Haley has answered better than I could about how to use an explicit catalog with Saxon.
As for using built-in copies of the well-known DTDs, Saxon 9.4 will indeed do this automatically by default if it recognizes the system ID or public ID of the required resource. If it's going to the W3C site, the first thing we need to discover is the precise form of the DOCTYPE you are using.
The error message about failure to load the Apache catalog resolver actually means that Saxon has been unable to load the class org.apache.xml.resolver.CatalogManager. I wonder if you're using a version of the resolver that doesn't include this class? I can't think of any other explanation.
From the saxonica link in your question:
This sounds to me like Saxon automatically uses local copies of the well-known W3C DTDs, but if you specify
-catalog
, it does not use the internal resolver and you have to specify these explicitly in your catalog.Here's a working example of using a catalog with Saxon...
File/directory structure of my example
XML DTD (
so_test/lib/test.dtd
)XML Instance (
so_test/test.xml
)Note that the system identifier points to a location that doesn't exist to make sure the catalog is being used.
XML Catalog (
so_test/lib/catalog.xml
)Command Line
Note the
-dtd
option to enable validation.Results
If I make the XML instance invalid:
and run the same command line as above, here is the result:
Hopefully this example will help you figure out what to change with your setup.
Also, using the
-t
option gives you additional information such as what catalog was loaded and if the public identifier was resolved:Additional Information
Saxon distributes the Apache version of Xerces, so use the
resolver.jar
found in the Apache Xerces distribution.