JAXP Factory Interfaces

Saxon implements a number of JAXP interfaces, notably the APIs for transformation, XPath processing, and validation.

XSLT

For transformation, the root object of the API is the JAXP TransformerFactory. Saxon provides several implementations of this interface:

The JAXP static method TransformerFactory.newInstance() searches the classpath for a JAR file containing a manifest that identifies it as a JAXP transformation engine. If it finds Saxon-HE on the classpath, it will instantiate net.sf.saxon.TransformerFactoryImpl; if it finds Saxon-PE, then ProfessionalTransformerFactory; if Saxon-EE, then EnterpriseTransformerFactory.

The TransformerFactory interface provides methods getAttribute(name) and setAttribute(name, value) which correspond directly to the methods getConfigurationProperty(name) and setConfigurationProperty(name, value) on the underlying Configuration object. By casting from the JAXP interface to the Saxon implementation class it is also possible to call the getConfiguration method which exposes the Configuration object directly.

The Saxon-PE and Saxon-EE implementations of the TransformerFactory also allow the configuration property CONFIGURATION_FILE to be set. The value is a filename containing the name of a configuration file, which must have the format described in Configuration file. This causes any previously-initialized configuration to be discarded, and replaced with a new Configuration object built from the settings in the specified configuration file.

XPath

Saxon implements the JAXP XPath interface javax.xml.xpath.XPathFactory; the implementation class is net.sf.saxon.xpath.XPathFactoryImpl.

However, the Saxon JAR files do not contain the manifest information that causes Saxon to be picked up as an XPath implementation by the factory method XPathFactory.newInstance(); it must be instantiated directly. This is because an application calling this method is probably expecting to find an XPath 1.0 engine, and is very likely to fail in some way if an XPath 3.1 engine is returned.

The JAXP XPathFactory interface is designed very much around (a) the XPath 1.0 type system, and (b) the DOM as the expected tree model. In addition, it only works with Saxon if the Configuration that underpins the XPathFactory is the same as the Configuration used to build the source document. Use of this interface with Saxon is therefore not very satisfactory, and the s9api interface is strongly preferred.

The JAXP XPathFactory interface has a general-purpose configuration mechanism in the form of the two methods setFeature() and getFeature(). These can be used to set/get all boolean-valued configuration options in the underlying Saxon Configuration, as well as the options defined in the JAXP interface itself. To set configuration options that are not boolean-valued, it is necessary to navigate to the underlying Configuration object and use its native interfaces. Saxon's implementation class for the XPathFactory is net.sf.saxon.xpath.XPathFactoryImpl, regardless which Saxon edition is in use.

XSD (Schema processing)

Saxon-EE also implements the JAXP SchemaFactory in class com.saxonica.ee.jaxp.SchemaFactoryImpl. The interface offers methods getProperty(name) and setProperty(name, value) which map to the underlying methods in the Saxon Configuration; again, it is also possible to cast to the Saxon implementation class and call configuration-setting methods directly.