Class XsdCompiler

java.lang.Object
net.sf.saxon.s9api.XsdCompiler
Direct Known Subclasses:
XsdCompilerEE

public abstract class XsdCompiler extends Object
The 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 Details

    • XsdCompiler

      public XsdCompiler()
  • Method Details

    • getProcessor

      public abstract Processor getProcessor()
      Get the associated s9api Processor
      Returns:
      the Processor
    • setXsdVersion

      public abstract void setXsdVersion(String version)
      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 property Feature.XSD_VERSION at the time the XsdSchemaCompiler is instantiated. By default this is "1.1".
      Parameters:
      version - the version of the XSD specification/language: either "1.0" or "1.1".
    • getXsdVersion

      public abstract String 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

      public abstract void setErrorReporter(ErrorReporter reporter)
      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

      public abstract 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

      public abstract void setSchemaURIResolver(SchemaURIResolver resolver)
      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 a Source representing the location where a schema document can be found.

      This SchemaURIResolver is used to dereference the URIs appearing in xs:import, xs:include, and xs:redefine declarations.

      Parameters:
      resolver - the SchemaURIResolver to be used during schema loading.
    • getSchemaURIResolver

      public abstract SchemaURIResolver 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

      public abstract XsdSchema compile(Source... source) throws SaxonApiException
      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 an XsdSchema object.

      This method can only be called once on a given SchemaManager object.

      If the source is a StreamSource or a SAXSource with no user-supplied XmlReader, then Saxon will allocate and configure an XmlReader. 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 an XmlReader and supplying this as a property of a SAXSource. For options when parsing included or imported stylesheet modules, it is possible to do the same in the SchemaURIResolver set using the setSchemaURIResolver(SchemaURIResolver) method.

      Parameters:
      source - the documents containing the schema. The getSystemId() method applied to each Source must return a base URI suitable for resolving xs:include and xs:import directives. 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

      public abstract XsdSchema compile(File... file) throws SaxonApiException
      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 an XsdSchema object.
      Parameters:
      file - the document containing the schema. The getSystemId() method applied to this Source must return a base URI suitable for resolving xs:include and xs:import directives. 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

      public abstract XsdSchema combine(XsdSchema... schemas) throws SaxonApiException
      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

      public abstract XsdSchema 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 using xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes. 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

      public abstract XsdSchema importComponents(Source source) throws SaxonApiException
      Import a precompiled Schema Component Model from a given Source. The result is delivered as an XsdSchema object.
      Parameters:
      source - the XML file containing the schema component model, as generated by a previous call on XsdSchema.exportComponents(net.sf.saxon.s9api.Destination)
      Returns:
      the schema produced by processing the supplied schema component model export file
      Throws:
      SaxonApiException
    • wrapInternalSchema

      public abstract XsdSchema wrapInternalSchema(Schema internalSchema)
      Construct an XsdSchema by wrapping an internal schema object. This is intended primarily for internal use
      Parameters:
      internalSchema - the internal schema object