Jacinto Resende
Jacinto Resende

Reputation: 443

Default SAX Parser in Java 8

I'm struggling to put some order in my mind about SAX/DOM integration with Java. I find the information over the Internet messy. I would appreciate if someone could answer some, probably knives, simple questions. Here's my environment:

My Questions

Upvotes: 3

Views: 2545

Answers (2)

Stephen C
Stephen C

Reputation: 718787

The version of the (default) Xerces parsers you have in your JVM depends on the Java build you are using. As you can see from https://bugs.openjdk.org/browse/JDK-8282280, the OpenJDK team will (if necessary) pull in an updated Xerces version into the OpenJDK code tree ... and backport the change to supported versions of Java.

There is an article in the Oracle Knowledgebase on how find out what a JVM's Xerces version is, but you need an Oracle Support account to read it:

Apparently on Java 8 you can find this out by running:

$ java com.sun.org.apache.xerces.internal.impl.Version

... but this doesn't work in later versions. (Perhaps, someone can comment to supply the new recipe?)


This Q&A is also relevant, but I don't think it answers the "what version" question for a JVM's builtin Xerces implementation:

Upvotes: 1

warrenc5
warrenc5

Reputation: 1

https://docs.oracle.com/javase/8/docs/api/javax/xml/parsers/SAXParserFactory.html

https://docs.oracle.com/javase/8/docs/api/javax/xml/parsers/SAXParserFactory.html#newInstance--

Obtain a new instance of a SAXParserFactory. This static method creates a new factory instance This method uses the following ordered lookup procedure to determine the SAXParserFactory implementation class to load:

Use the javax.xml.parsers.SAXParserFactory system property.
Use the properties file "lib/jaxp.properties" in the JRE directory. This configuration file is in standard java.util.Properties format and contains the fully qualified name of the implementation class with the key being the system property defined above. The jaxp.properties file is read only once by the JAXP implementation and it's values are then cached for future use. If the file does not exist when the first attempt is made to read from it, no further attempts are made to check for its existence. It is not possible to change the value of any property in jaxp.properties after it has been read for the first time.
Use the service-provider loading facilities, defined by the ServiceLoader class, to attempt to locate and load an implementation of the service using the default loading mechanism: the service-provider loading facility will use the current thread's context class loader to attempt to load the service. If the context class loader is null, the system class loader will be used.
Otherwise the system-default implementation is returned.

Once an application has obtained a reference to a SAXParserFactory it can use the factory to configure and obtain parser instances.

Upvotes: 0

Related Questions