The s9api interface allows schemas to be loaded into a Processor, and then to be used for validating instances, or for schema-aware XSLT and XQuery processing.
The main steps are:
Create a Processor (net.sf.saxon.s9api.Processor
) and call its
getSchemaManager()
method to get a SchemaManager.
If required, set options on the SchemaManager to control the way in which schema documents will be loaded.
Load a schema document by calling the load()
method, which takes a JAXP
Source object as its argument. The resulting schema document is available to all applications run within
the containing Processor
.
To validate an instance document, call the newSchemaValidator
method on the
SchemaManager
object.
Set options on the SchemaValidator
to control the way in which a particular validation
episode is performed, and then invoke its validate()
method to validate an instance document.
Note that additional schemas referenced from the xsi:schemaLocation
attributes
within the source documents will be loaded as necessary. A target namespace is ignored if there is already
a loaded schema for that namespace; Saxon makes no attempt to load multiple schemas for the same
namespace and check them for consistency.
Although the API is defined in such a way that a SchemaValidator
is created for a particular SchemaManager
, in the Saxon implementation the schema components that
are available to the validator are not only the components within that schema, but all the components that form part
of any schema registered with the Processor
(or indeed, with the underlying Configuration
)
The SchemaValidator
implements the Destination
interface, which means it can be used to receive
input from any process that writes to a Destination
, for example an XSLT transformation or an XQuery query.
The result of validation can also be sent to any Destination
, for example an XSLT transformer.