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

 string Catalog

This property provides a way to set the catalog file which will be used by the Apache catalog resolver.

 IList<StaticError> ErrorList

Deprecated IList<StaticError> ErrorList is deprecated, please use the method SetErrorList and GetErrorList.

 IErrorReporter 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 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.

 string XsdVersion

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

 

Method Summary

 void Compile(Stream input, Uri baseUri)

Compile a schema supplied as a Stream. 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.

 XdmAtomicType GetAtomicType(QName qname)

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

 IList<XmlProcessingError> GetErrorList()

Get list of errors as IList<XmlProcessingError>

 SchemaValidator NewSchemaValidator()

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

 void SetErrorList(IList<XmlProcessingError> value)

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.

 

Property Detail

Catalog

public string Catalog {set; }

This property provides a way to set the catalog file which will be used by the Apache catalog resolver.

ErrorList

public IList<StaticError> ErrorList {get; set; }

Deprecated IList<StaticError> ErrorList is deprecated, please use the method SetErrorList and GetErrorList.

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.

ErrorReporter

public IErrorReporter 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 {get; set; }

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

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,
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(Uri uri)

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

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.

GetErrorList

public IList<XmlProcessingError> GetErrorList()

Get list of errors as IList<XmlProcessingError>

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

SetErrorList

public void SetErrorList(IList<XmlProcessingError> value)

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.

Parameters:

value - Supplied list.