Configuring DocumentBuilderFactory to use the system's builder factory
843834Jan 2 2010 — edited Jan 6 2010Hi,
I wrote a plugin for some application. The plugin uses a DocumentBuilder to read and write XML, so it first calls DocumentBuilderFactory.newInstance() to obtain a factory. As the documentation says, the factory implementation is looked up in various places, in order to enable users to override the factory that is included with the JVM.
It turns out that some other plugins of the application configure the system properties to use their own implementation, so by calling DocumentBuilderFactory.newInstance() I end up with a DocumentBuilder from the other plugins, which happens to be buggy. I would like my plugin to always use the implementation included in the JVM. How do I do this?
(I noticed that DocumentBuilderFactory.newInstance() in my implementation uses "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl" as the default factory. Is it the same in all JVMs? If it is, I can simply replace the call to "newInstance" with creating a new instance of this xerces implementation.)
Thanks,
Shlomy