JAXP Factory Interfaces
Saxon implements a number of JAXP interfaces, notably the APIs for transformation, XPath processing, and validation.
For transformation, the root object of the API is the JAXP
TransformerFactory. Saxon provides several implementations of this interface:
- For any Saxon edition: net.sf.saxon.TransformerFactoryImpl. This creates the "highest possible" configuration based on what software is in use (without taking into account what license file is deployed). An application creating an instance of this class can therefore use Saxon-PE or Saxon-EE facilities if they are available.
- For Saxon-HE: net.sf.saxon.BasicTransformerFactory. This strictly disables all Saxon-PE and Saxon-EE features.
- For Saxon-PE: com.saxonica.config.ProfessionalTransformerFactory
- For Saxon-EE: com.saxonica.config.EnterpriseTransformerFactory
- For streaming with Saxon-EE: com.saxonica.config.StreamingTransformerFactory.
TransformerFactorydoes not fully comply with the JAXP specifications, because (in the interests of enabling streaming) it does not set the global context item to the root node of the source document; if any global variables in the stylesheet refer to the context item, this will cause a streaming failure.
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
if it finds Saxon-PE, then
ProfessionalTransformerFactory; if Saxon-EE, then
TransformerFactory interface provides methods
setAttribute(name, value) which correspond directly
to the methods
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.
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.
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
used to build the source document. Use of this interface with Saxon is therefore not very satisfactory, and the s9api interface is strongly preferred.
XPathFactory interface has a general-purpose configuration mechanism in the form of the two methods
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
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
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.