In order to use XML Catalogs with Xerces, the
Apache XML Commons Resolver:
resolver.jar
needs to be on your classpath (or accessible
in some other way to the ClassLoader). The resolver provides an implementation
of OASIS XML Catalogs v1.1
as well as some other catalog formats. The XML Commons Resolver 1.2 is included with
the binary distribution of Xerces. For information about interacting directly with
the Resolver's API visit the XML Commons
site.
As a convenience for users the parser provides a utility class:
org.apache.xerces.util.XMLCatalogResolver
which encapsulates
the XML Commons Resolver exposing methods relevant to resolving XML entities.
It implements the (org.apache.xerces.xni.parser.XMLEntityResolver
)
XNI entity resolver, the (org.xml.sax.EntityResolver
) SAX entity resolver
and the (org.w3c.dom.ls.LSResourceResolver
) DOM resource resolver
interfaces. In XMLCatalogResolver
the resolveEntity methods only query the
catalog for a mapping of the given identifier. These methods may be overridden if
other behaviour is required.
To use XMLCatalogResolver
as an XNI EntityResolver you need
to do something like this:
| | |
| import org.apache.xerces.util.XMLCatalogResolver;
import org.xml.sax.*;
...
XMLReader reader;
String [] catalogs =
{"file:///C:/catalog/cat1.xml", "file:///C:/catalog/cat2.xml"};
...
// Create catalog resolver and set a catalog list.
XMLCatalogResolver resolver = new XMLCatalogResolver();
resolver.setPreferPublic(true);
resolver.setCatalogList(catalogs);
// Set the resolver on the parser.
reader.setProperty(
"http://apache.org/xml/properties/internal/entity-resolver",
resolver);
... | |
| | |
Note that setting an XNI entity resolver on a SAX or DOM parser will
replace any type of entity resolver which was previously registered. If
some other type of resolver is registered on the parser it will replace
any XNI entity resolver previously registered.
In addition to being used as an entity resolver, it is intended that
the XMLCatalogResolver
may be used standalone to perform
catalog resolution outside of a parsing context. It may also be shared
between several parsers and the application. See the API
documentation for details.
|
The XMLCatalogResolver class requires the XML Commons Resolver 1.1
or a version compatible with 1.1.
|