Enable Catalog Support

To enable the support for the XML Catalogs feature on a processor, the USE_CATALOG feature must be set to true, and at least one catalog entry file specified.

USE_CATALOG

A Java XML processor determines whether the XML Catalogs feature is supported based on the value of the USE_CATALOG feature. By default, USE_CATALOG is set to true for all JDK XML Processors. The Java XML processor further checks for the availability of a catalog file, and attempts to use the XML Catalog API only when the USE_CATALOG feature is true and a catalog is available.

The USE_CATALOG feature is supported by the XML Catalog API, the system property, and the jaxp.properties file. For example, if USE_CATALOG is set to true and it’s desirable to disable the catalog support for a particular processor, then this can be done by setting the USE_CATALOG feature to false through the processor's setFeature method. The following code sets the USE_CATALOG feature to the specified value useCatalog for an XMLReader object:

SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
XMLReader reader = spf.newSAXParser().getXMLReader();
if (setUseCatalog) {
   reader.setFeature(XMLConstants.USE_CATALOG, useCatalog); 
}

On the other hand, if the entire environment must have the catalog turned off, then this can be done by configuring the jaxp.properties file with a line:

 javax.xml.useCatalog = false;

javax.xml.catalog.files

The javax.xml.catalog.files property is defined by the XML Catalog API and supported by the JDK XML processors, along with other catalog features. To employ the catalog feature on a parsing, validating, or transforming process, all that’s needed is to set the FILES property on the processor, through its system property or using the jaxp.properties file.

Catalog URI

The catalog file reference must be a valid URI, such as file:///users/auser/catalog/catalog.xml.

The URI reference in a system or a URI entry in the catalog file can be absolute or relative. If they’re relative, then they are resolved using the catalog file's URI or a base URI if specified.

Using system or uri Entries

When using the XML Catalog API directly (see XML Catalog API Interfaces for an example), system and uri entries both work when using the JDK XML Processors' native support of the CatalogFeatures class. In general, system entries are searched first, then public entries, and if no match is found then the processor continues searching uri entries. Because both system and uri entries are supported, it’s recommended that you follow the custom of XML specifications when selecting between using a system or uri entry. For example, DTDs are defined with a systemId and therefore system entries are preferable.