It is possible to override the default parser configuration used
by the Xerces2 parsers without writing any code or changing the
existing parser classes. Moreover, the DOM and SAX parsers created
using the JAXP interfaces will use the specified parser configuration
transparently and without need to call additional methods to set the
parser configuration.
The DOM and SAX parsers decide which parser configuration to use in
the following order:
-
First, the
org.apache.xerces.xni.parser.XMLParserConfiguration
system property is queried for the class name of the parser configuration.
-
Next, if a file called
xerces.properties
exists in the lib
subdirectory of the JRE installation and the
org.apache.xerces.xni.parser.XMLParserConfiguration
property
is defined it, then its value will be read from the file.
-
Next, the
org.apache.xerces.xni.parser.XMLParserConfiguration
file is requested from the META-INF/services/
directory.
This file contains the class name of the parser configuration.
-
Finally, the
org.apache.xerces.parsers.XIncludeAwareParserConfiguration
is used as the default parser configuration.
|
In all cases, the parser configuration class must have a public,
no argument constructor so that it can be instantiated dynamically.
|
When using Java 2, it is not necessary to rebuild the Xerces jar files
in order to override the default parser configuration using the first
method. As long as a JAR file containing the appropriate file exists
in the META-INF/services/
directory appears before
the Xerces JAR files, the parser will use the new parser configuration.
The first method can always be used on the command line for the JVM
by using the -D
option. For example, to override the
default parser configuration using a custom configuration named
MyConfig
, use the following command line:
| | |
| java -Dorg.apache.xerces.xni.parser.XMLParserConfiguration=MyConfig application_class | |
| | |