Saxon.Api

 

 

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

 ErrorReporter ErrorReporter

Set the ErrorReporter to be used when validating instance documents as a user defined ErrorReporter. If this property is used then the ErrorList property and SetErrorList method is overriden

 SchemaResolver SchemaResolver

The SchemaResolver is a user-supplied callback used for resolving references to schema documents. It applies to references from one schema document to another appearing in xs:import, xs:include, xs:override, 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.

 string XsdVersion

The version of the W3C XML Schema Specification handled by this SchemaManager.

 

Method Summary

 void Compile (Stream input)

Compile a schema supplied as a Stream. The resulting schema components are added to the cache. The base URI of the schema document is taken as the current working directory.

 void Compile (Stream input, Uri baseUri)

Compile a schema supplied as a Stream. The resulting schema components are added to the cache.

 void Compile (TextReader input)

Compile a schema supplied as a TextReader. The resulting schema components are added to the cache. The base URI of the schema document is taken as the current working directory.

 void Compile (TextReader input, Uri baseUri)

Compile a schema supplied as a TextReader. The resulting schema components are added to the cache.

 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 XmlReader. The resulting schema components are added to the cache.

 void Compile (XdmNode node)

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.

 XdmNode ExportComponents ()

Export schema components to an SCM file, available using a subsequent call on ImportComponents.

 XdmAtomicType GetAtomicType (QName qname)

Factory method to get an AtomicType object representing the atomic type with a given QName.

 void ImportComponents (XdmNode schemaComponentModel)

Import schema components from an SCM file, produced using a previous call on ExportComponents.

 SchemaValidator NewSchemaValidator ()

Create a new SchemaValidator, which may be used for validating instance documents.

 

Property Detail

ErrorReporter

public ErrorReporter ErrorReporter {set; }

Set the ErrorReporter to be used when validating instance documents as a user defined ErrorReporter. If this property is used then the ErrorList property and SetErrorList method is overriden

The IErrorReporter to be used

SchemaResolver

public SchemaResolver SchemaResolver {set; }

The SchemaResolver is a user-supplied callback used for resolving references to schema documents. It applies to references from one schema document to another appearing in xs:import, xs:include, xs:override, 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.

If no SchemaResolver is supplied, or if the supplied SchemaResolver returns null, then the system attempts to locate a schema using the common resource resolver associated with the Saxon Configuration. It first attempts to resolve the location hint (if available), then the target namespace (if present and non-empty). If both attempts fail, the system then attempts to use standard URI resolution mechanisms to resolve the location hint (if available); it does not attempt to resolve the target namespace.

XsdVersion

public string XsdVersion {get; set; }

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

public void Compile(Stream input)

Compile a schema supplied as a Stream. The resulting schema components are added to the cache. The base URI of the schema document is taken as the current working directory.

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.

Compile

public void Compile(Stream input,
Uri baseUri)

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

Compile

public void Compile(TextReader input)

Compile a schema supplied as a TextReader. The resulting schema components are added to the cache. The base URI of the schema document is taken as the current working directory.

Parameters:

input - A TextReader that supplies the source text of the schema. This method will consume the supplied stream. It is the caller's responsibility to close the reader after use.

Compile

public void Compile(TextReader input,
Uri baseUri)

Compile a schema supplied as a TextReader. The resulting schema components are added to the cache.

Parameters:

input - A TextReader that supplies the source text of the schema. This method will consume the supplied stream. It is the caller's responsibility to close the reader after use.
baseUri - The base URI of the schema document, for resolving any references to other schema documents

Compile

public void Compile(Uri uri)

Compile a schema, retrieving the source using a URI. The resulting schema components are added to the cache.

The supplied URI is resolved, where possible, using the configuration-level resource resolver. The SchemaResolver is not used.

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 found

Compile

public void Compile(XmlReader reader)

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 document

Compile

public void Compile(XdmNode node)

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.

ExportComponents

public XdmNode ExportComponents()

Export schema components to an SCM file, available using a subsequent call on ImportComponents.

The returned SCM tree will typically be serialized to a file, so that it can be reused whenever a schema is required. Most Saxon APIs that accept a source XSD schema will also accept a lexical SCM file in its place.

Returns:

The XML representation of the SCM.

GetAtomicType

public XdmAtomicType GetAtomicType(QName qname)

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 type

Returns:

An AtomicType object representing this type if it is present in this schema (and is an atomic type); otherwise, null.

ImportComponents

public void ImportComponents(XdmNode schemaComponentModel)

Import schema components from an SCM file, produced using a previous call on ExportComponents.

Parameters:

schemaComponentModel - The XML representation of the SCM.

NewSchemaValidator

public SchemaValidator 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>.