Class XsdCompiler
- Direct Known Subclasses:
XsdCompilerEE
XsdCompiler is used to load schema documents, and to set options for the way in
which they are loaded.
The XsdCompiler is new in Saxon 13; it replaces the class SchemaManager
which is retained (but deprecated) to provide a degree of backwards compatibility.
A schema, represented by an XsdSchema object, is a collection of schema components,
which may come from one schema document or from a collection of schema documents.
An XsdCompiler is used to create XsdSchema objects from source
schema documents.
Schema processing requires Saxon-EE. The abstract class XsdCompiler exists in Saxon-HE
and Saxon-PE, but is never instantiated.
In Saxon-EE the subclass XsdCompilerEE is instantiated to do the heavy lifting, but this
is not normally exposed to users.
An XsdCompiler is created using the factory method Processor.newXsdCompiler(). The normal pattern
of usage is to set options, then call compile(File...) or compile(Source...) to compile
one or more schema documents into a schema. The schema can be used to validate instance documents using
the method XsdSchema.newValidator(), and it can be added to the static context of XQuery queries
and XSLT stylesheets using the methods XQueryCompiler.useSchema(XsdSchema) and
XsltCompiler.useSchema(String, XsdSchema).
- Since:
- 13.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract XsdSchemaCombine a set of schemas into oneabstract XsdSchemaLoad a schema document from a given File or set of files.abstract XsdSchemaLoad a schema document from a given Source.abstract XsdSchemaReturn an empty schema.abstract ErrorReporterGet the ErrorReporter being used while loading and validating schema documentsabstract ProcessorGet the associated s9apiProcessorabstract SchemaURIResolverGet the SchemaURIResolver to be used during schema loading.abstract StringGet the version of XSD in use for this schema.abstract XsdSchemaimportComponents(Source source) Import a precompiled Schema Component Model from a given Source.abstract voidsetErrorReporter(ErrorReporter reporter) Set the ErrorReporter to be used while loading and validating schema documentsabstract voidsetSchemaURIResolver(SchemaURIResolver resolver) Set the SchemaURIResolver to be used during schema loading.abstract voidsetXsdVersion(String version) Set the version of XSD in use for this schema.abstract XsdSchemawrapInternalSchema(Schema internalSchema) Construct anXsdSchemaby wrapping an internal schema object.
-
Constructor Details
-
XsdCompiler
public XsdCompiler()
-
-
Method Details
-
getProcessor
Get the associated s9apiProcessor- Returns:
- the
Processor
-
setXsdVersion
Set the version of XSD in use for this schema. The value must be "1.0" or "1.1". The default is taken from the configuration propertyFeature.XSD_VERSIONat the time theXsdSchemaCompileris instantiated. By default this is "1.1".- Parameters:
version- the version of the XSD specification/language: either "1.0" or "1.1".
-
getXsdVersion
Get the version of XSD in use for this schema. The value will be "1.0" or "1.1"- Returns:
- the version of XSD in use.
-
setErrorReporter
Set the ErrorReporter to be used while loading and validating schema documents- Parameters:
reporter- The error reporter to be used. This is notified of all errors detected during the compilation. May be set to null to revert to the default ErrorReporter.
-
getErrorReporter
Get the ErrorReporter being used while loading and validating schema documents- Returns:
- reporter The error reporter in use. This is notified of all errors detected during the compilation. Returns null if no user-supplied ErrorReporter has been set.
-
setSchemaURIResolver
Set the SchemaURIResolver to be used during schema loading. This SchemaURIResolver, despite its name, is not used for resolving relative URIs against a base URI; it is used for dereferencing an absolute URI (after resolution) to return aSourcerepresenting the location where a schema document can be found.This SchemaURIResolver is used to dereference the URIs appearing in
xs:import,xs:include, andxs:redefinedeclarations.- Parameters:
resolver- the SchemaURIResolver to be used during schema loading.
-
getSchemaURIResolver
Get the SchemaURIResolver to be used during schema loading.- Returns:
- the URIResolver used during stylesheet compilation. Returns null if no user-supplied URIResolver has been set.
-
compile
Load a schema document from a given Source. The schema components derived from this schema document are retained by this SchemaManager as the current schema, and are also returned by the method as anXsdSchemaobject.This method can only be called once on a given
SchemaManagerobject.If the source is a
StreamSourceor aSAXSourcewith no user-suppliedXmlReader, then Saxon will allocate and configure anXmlReader. This will NOT take account of any configuration level parser settings (such as DTD validation, XInclude processing, and so on). The recommended way to customise parsing options is by creating anXmlReaderand supplying this as a property of aSAXSource. For options when parsing included or imported stylesheet modules, it is possible to do the same in theSchemaURIResolverset using thesetSchemaURIResolver(SchemaURIResolver)method.- Parameters:
source- the documents containing the schema. The getSystemId() method applied to each Source must return a base URI suitable for resolvingxs:includeandxs:importdirectives. The document may be either a schema document in source XSD format, or a compiled schema in Saxon-defined SCM format.- Returns:
- the resulting schema.
- Throws:
SaxonApiException- if any of the schema documents is not valid, or if there are conflicts between the schema documents.
-
compile
Load a schema document from a given File or set of files. The schema components derived from this schema document are retained by this SchemaManager as the current schema, and are also returned by the method as anXsdSchemaobject.- Parameters:
file- the document containing the schema. The getSystemId() method applied to this Source must return a base URI suitable for resolvingxs:includeandxs:importdirectives. The document may be either a schema document in source XSD format, or a compiled schema in Saxon-defined SCM format (as produced using the -export option)- Returns:
- the resulting schema.
- Throws:
SaxonApiException- if the schema document is not valid.- Since:
- 12.0
-
combine
Combine a set of schemas into one- Parameters:
schemas- the input schemas. These are not modified.- Returns:
- the combined schema
- Throws:
SaxonApiException- if the schemas are not compatible, for example if they contain duplicate names.- Since:
- 13.0
-
emptySchema
Return an empty schema. This contains only the built-in schema components This may be useful for validating instance documents when all the actual schema definitions are linked from the instance document usingxsi:schemaLocationandxsi:noNamespaceSchemaLocationattributes. It can also be used directly, for example, to validate elements that have an xsi:type attribute naming a built-in atomic type such as xs:ID.- Returns:
- a minimal schema containing only the built-in schema components
-
importComponents
Import a precompiled Schema Component Model from a given Source. The result is delivered as anXsdSchemaobject.- Parameters:
source- the XML file containing the schema component model, as generated by a previous call onXsdSchema.exportComponents(net.sf.saxon.s9api.Destination)- Returns:
- the schema produced by processing the supplied schema component model export file
- Throws:
SaxonApiException
-
wrapInternalSchema
Construct anXsdSchemaby wrapping an internal schema object. This is intended primarily for internal use- Parameters:
internalSchema- the internal schema object
-