Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It is quite difficult to predict what concrete JAXP factory implementation will be loaded without actually creating an instance because the process for selecting an implementation. </p> <p>From the <a href="https://jaxp.java.net/1.4/JAXP-FAQ.html#pluggability" rel="noreferrer">Official JAXP FAQ</a> (Question 14):</p> <blockquote> <p>When an application wants to create a new JAXP <code>DocumentBuilderFactory</code> instance, it calls the staic method <code>DocumentBuilderFactory.newInstance()</code>. This causes a search for the name of a concrete subclass of <code>DocumentBuilderFactory</code> using the following order:</p> <ol> <li>The value of a system property like <code>javax.xml.parsers.DocumentBuilderFactory</code> if it exists and is accessible.</li> <li>The contents of the file <code>$JAVA_HOME/jre/lib/jaxp.properties</code> if it exists.</li> <li>The Jar Service Provider discovery mechanism specified in the Jar File Specification. A jar file can have a resource (i.e. an embedded file) such as <code>META-INF/services/javax.xml.parsers.DocumentBuilderFactory</code> containing the name of the concrete class to instantiate.</li> <li>The fallback platform default implementation.</li> </ol> </blockquote> <p>Adding to this complexity, each individual JAXP factory can have an independent implementation specified. It is common to use one parser implementation and another XSLT implementation, but the granularity of the selection mechanism above allows you to mix and match to an even greater degree.</p> <p><strong>The following code will output information about the four main JAXP factories:</strong></p> <pre><code>private static void OutputJaxpImplementationInfo() { System.out.println(getJaxpImplementationInfo("DocumentBuilderFactory", DocumentBuilderFactory.newInstance().getClass())); System.out.println(getJaxpImplementationInfo("XPathFactory", XPathFactory.newInstance().getClass())); System.out.println(getJaxpImplementationInfo("TransformerFactory", TransformerFactory.newInstance().getClass())); System.out.println(getJaxpImplementationInfo("SAXParserFactory", SAXParserFactory.newInstance().getClass())); } private static String getJaxpImplementationInfo(String componentName, Class componentClass) { CodeSource source = componentClass.getProtectionDomain().getCodeSource(); return MessageFormat.format( "{0} implementation: {1} loaded from: {2}", componentName, componentClass.getName(), source == null ? "Java Runtime" : source.getLocation()); } </code></pre> <p><strong>The following sample output</strong> illustrates a mix-and-match of three different JAXP implementations (Built-in Xerces and external JARs for Xerces 2.8 and Xalan) working together:</p> <pre><code>DocumentBuilderFactory implementation: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl loaded from: file:/C:/Projects/Scratch/lib/xerces-2.8.0.jar XPathFactory implementation: com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl loaded from: Java Runtime TransformerFactory implementation: org.apache.xalan.processor.TransformerFactoryImpl loaded from: file:/C:/Projects/Scratch/lib/xalan.jar SAXParserFactory implementation: org.apache.xerces.jaxp.SAXParserFactoryImpl loaded from: file:/C:/Projects/Scratch/lib/xerces-2.8.0.jar </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload