![]() | ![]() | ![]() | ![]() | ![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]() | ![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]()
|
How to fetch DTDs and XML Schemas from JAR files using CastorIntended Audience Prerequisites What Dependencies? An Introduction to the EntityResolver The Castor DTDResolver The Hitch: Defining the Correct IDs References Intended AudienceAnyone who wants to retrieve DTDs and/or schemas from a local JAR file rather than the network. This document helps people to get familiar with the basic concepts and discusses some implementation details. PrerequisitesNone. All the required files reside in the Castor JAR, but what version of Castor you have will determine the public/system IDs are recognized by the DTDResolver. What Dependencies?XML files often reference other files. The most common dependencies are either document type definitions (DTDs) from the DOCTYPE declaration or XML Schemas from the schemaLocation attribute. Parsers usually only request schemas for validation, but more parsers are now requesting the DTDs whether validation is on or off. This allows the parser to resolve any entity references (i.e. & or <) that might be used in the document and defined in the DTD. This behavior can cause problems for machines with limited network connectivity, and in certain situations it is simply undesirable to have the parser going to the internet for each dependency. An Introduction to the EntityResolverThe org.xml.sax.EntityResolver interface is the key to retrieving XML dependencies from locations other than the defined system location. The interface has one method:
During parsing, before it attempts to retrieve any external files, the parser will call the above method, giving the public and/or system ID for the file. The implementing object can then either return an InputSource through which the parser can access the file, or null if the parser should fetch the file via normal channels. The Castor DTDResolverIn Castor, the org.exolab.castor.util.DTDResolver class provides an implementation of EntityResolver that is designed to fetch all the Castor dependencies from the Castor JAR file. This includes:
Castor automatically uses a DTDResolver when loading a mapping file, but must be told to use one during unmarshalling:
The DTDResolver can also wrap another EntityResolver to allow resolver chaining. DTDResolver calls the nested EntityResolver before attempting to resolve the ID(s) itself. The Hitch: Defining the Correct IDsFor the DTDResolver to retrieve the desired file from the Castor JAR, either the public ID or the system ID must match exactly. Below are lists of public and system IDs for the versions of Castor, but when in doubt, check the code of DTDResolver. Since Castor v0.9.9.1 the following IDs are preferred:
For older distributions, the following IDs have been accepted since Castor v0.9.5:
References
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() ![]() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |