Saxon.Api
Class SchemaManager
-
public class SchemaManager
A SchemaManager
is responsible for compiling schemas and
maintaining a cache of compiled schemas that can be used for validating
instance documents.
To obtain a SchemaManager
, use the
SchemaManager
property of the Processor
object.
In a schema-aware Processor
there is exactly one
SchemaManager
(in a non-schema-aware Processor
there is none).
The cache of compiled schema definitions can include only one schema component (for example a type, or an element declaration) with any given name. An attempt to compile two different schemas in the same namespace will usually therefore fail.
As soon as a type definition or element declaration is used for the first
time in a validation episode, it is marked as being "sealed": this prevents subsequent
modifications to the component. Examples of modifications that are thereby disallowed
include adding to the substitution group of an existing element declaration, adding
subtypes
to an existing type, or redefining components using <xs:redefine>
.
Property Summary |
|
---|---|
string | Catalog This property provides a way to set the catalog file which will be used by the Apache catalog resolver. |
IList<StaticError> | ErrorList
List of errors. The caller may supply an empty list before calling |
SchemaResolver | SchemaResolver
The |
string | XsdVersion
The version of the W3C XML Schema Specification handled by this |
Method Summary |
|
---|---|
void | Compile(Stream input, Uri baseUri)
Compile a schema supplied as a |
void | Compile(Uri uri) Compile a schema, retrieving the source using a URI. The resulting schema components are added to the cache. |
void | Compile(XmlReader reader)
Compile a schema, delivered using an |
void | Compile(XdmNode node)
Compile a schema document, located at an |
XdmAtomicType | GetAtomicType(QName qname)
Factory method to get an |
SchemaValidator | NewSchemaValidator()
Create a new |
Property Detail
Catalog
This property provides a way to set the catalog file which will be used by the Apache catalog resolver.
ErrorList
List of errors. The caller may supply an empty list before calling Compile
;
the processor will then populate the list with error information obtained during
the schema compilation. Each error will be included as an object of type StaticError
.
If no error list is supplied by the caller, error information will be written to
the standard error stream.
By supplying a custom List
with a user-written add()
method, it is possible to
intercept error conditions as they occur.
Note that this error list is used only for errors detected during the compilation of the schema. It is not used for errors detected when using the schema to validate a source document.
SchemaResolver
The SchemaResolver
is a user-supplied class used for resolving references to
schema documents. It applies to references from one schema document to another
appearing in xs:import
, xs:include
, and xs:redefine
; to
references from an instance document to a schema in xsi:schemaLocation
and
xsi:noNamespaceSchemaLocation
, to xsl:import-schema
in XSLT, and to
the import schema
declaration in XQuery.
XsdVersion
The version of the W3C XML Schema Specification handled by this SchemaManager
.
The value must be "1.0" (indicating XML Schema 1.0) or "1.1" (indicating XML Schema 1.1). The default is "1.0". New constructs defined in XSD 1.1 are rejected unless this property is set to "1.1" before compiling the schema.
Method Detail
Compile
Compile a schema, retrieving the source using a URI. The resulting schema components are added to the cache.
The document located via the URI is parsed using the System.Xml
parser.
Parameters:
uri
- The URI identifying the location where the schema document can be
foundCompile
Compile a schema, delivered using an XmlReader
. The resulting schema components are added
to the cache.
The XmlReader
is responsible for parsing the document; this method builds a tree
representation of the document (in an internal Saxon format) and compiles it.
The XmlReader
is used as supplied; it is the caller's responsibility to ensure that
its settings are appropriate for parsing a schema document (for example, that entity
references
are expanded and whitespace is retained).
Parameters:
reader
- The XmlReader
(that is, the XML parser) used to supply the source schema documentCompile
Compile a schema document, located at an XdmNode
. This may be a document node whose
child is an xs:schema
element, or it may be
the xs:schema
element itself. The resulting schema components are added
to the cache.
Parameters:
node
- The document node or the outermost element node of a schema document.GetAtomicType
Factory method to get an AtomicType
object representing the atomic type with a given QName
.
It is undefined whether two calls on this method supplying the same QName
will return the same
XdmAtomicType
object instance.
Parameters:
qname
- The QName
of the required typeReturns:
AtomicType
object representing this type if it is present in this schema (and is an
atomic type); otherwise, null. NewSchemaValidator
Create a new SchemaValidator
, which may be used for validating instance
documents.
The SchemaValidator
uses the cache of schema components held by the
SchemaManager
. It may also add new components to this cache (for example,
when the instance document references a schema using xsi:schemaLocation
).
It is also affected by changes to the schema cache that occur after the
SchemaValidator
is created.
When schema components are used for validating instance documents (or for compiling
schema-aware queries and stylesheets) they are sealed to prevent subsequent modification.
The modifications disallowed once a component is sealed include adding to the substitution
group
of an element declaration, adding subtypes derived by extension to an existing complex
type, and
use of <xs:redefine>
.
Compile a schema supplied as a
Stream
. The resulting schema components are added to the cache.Parameters:
input
- A stream containing the source text of the schema. This method will consume the supplied stream. It is the caller's responsibility to close the stream after use.baseUri
- The base URI of the schema document, for resolving any references to other schema documents