Using xml resolvers and DOM

Read the related article on xml resolvers so you understand why we use resolvers.

Tutorial and Sample code

You will need to download and install the xml-commons-resolver package which is part of the xml-commons components from apache.

The example below assumes that you have already created your catalog file at D:\cygwin\usr\share\catalog\docbook.catalog, and we want to specifiy this explicitly within our code. There are other ways to setup the catalog, read the documentation to see which one suits your needs.


...
CatalogManager cm = new CatalogManager();
cm.setCatalogFiles("D:\\cygwin\\usr\\share\\catalog\\docbook.catalog");
cm.setIgnoreMissingProperties(true);
CatalogResolver cr = new CatalogResolver(cm);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db;
db = dbf.newDocumentBuilder();
db.setEntityResolver(cr);
...
    

You need to have the line


      cm.setIgnoreMissingProperties(true);
      

otherwise it will complain to standard error with:


      Cannot find CatalogManager.properties
      

It is set to complain by default, but in this case it is turned off because we know we'll be specifying the catalog files with the setCatalogFiles method.

Alternatively, you can use the system property "xml.catalog.files" to set the catalog files.

Published: Wednesday, 18 August 2004