### Saxon.Api

- BinaryResource
- CatalogCollection
- DirectoryCollection
- DocumentBuilder
- DomDestination
- DynamicContext
- DynamicError
- EmptyEnumerator<T>
- ErrorReporter
- ErrorReporterToStaticError
- ErrorReporterWrapper
- ExtensionFunction
- ExtensionFunctionCall
- ExtensionFunctionDefinition
- Feature<T>
- FeatureKeys
- HostLanguage
- ICollectionFinder
- IErrorReporter
- IInvalidityHandler
- IMessageListener
- IMessageListener2
- InvalidityHandlerWrapper
- IPredicate<in XdmItem>
- IQueryResolver
- IResource
- IResourceCollection
- IResourceFactory
- IResultDocumentHandler
- IXmlLocation
- JarCollection
- NamespaceConstant
- NullDestination
- Predicate<T>
- Predicates
- Processor
- QName
- RawDestination
- RecoveryPolicy
- Resource
- ResourceCollection
- SchemaManager
- SchemaResolver
- SchemaValidationMode
- SchemaValidator
- Serializer
- StandardCollectionFinder
- StandardLogger
- StaticContext
- StaticError
- Step<TInput, TResult>
- Steps
- TextWriterDestination
- TreeModel
- URIQueryParameters
- ValidationFailure
- WhitespacePolicy
- XdmAnyArrayType
- XdmAnyFunctionType
- XdmAnyItemType
- XdmAnyMapType
- XdmAnyNodeType
- XdmArray
- XdmAtomicType
- XdmAtomicValue
- XdmAxis
- XdmDestination
  - - TreeProtector
- XdmEmptySequence
- XdmExternalObjectValue
- XdmFunctionItem
- XdmItem
- XdmItemType
- XdmMap
- XdmNode
- XdmNodeKind
- XdmSequenceType
- XdmValue
- XmlDestination
- XmlProcessingError
- XmlResource
- XPathCompiler
- XPathExecutable
- XPathSelector
- XQueryCompiler
- XQueryEvaluator
- XQueryExecutable
- Xslt30Transformer
- XsltCompiler
- XsltExecutable
  - - ParameterDetails
- XsltPackage
- XsltTransformer

### Saxon.Api

# Class SchemaValidator

public class SchemaValidator

A `SchemaValidator` is an object that is used for validating instance documents against a schema. The schema consists of the collection of schema components that are available within the schema cache maintained by the `SchemaManager`, together with any additional schema components located during the course of validation by means of an `xsl:schemaLocation` or `xsi:noNamespaceSchemaLocation` attribute within the instance document.

If validation fails, an exception is thrown. If validation succeeds, the validated document can optionally be written to a specified destination. This will be a copy of the original document, augmented with default values for absent elements and attributes, and carrying type annotations derived from the schema processing. Saxon does not deliver the full PSVI as described in the XML schema specifications, only the subset of the PSVI properties featured in the XDM data model.

### Property Summary
QName | DocumentElementName The name of the required top-level element of the document to be validated (that is, the name of the outermost element of the document). if no value is supplied, there is no constraint on the required type
QName | DocumentElementTypeName The name of the required type of the top-level element of the document to be validated. QName of the name of the required type of the document element, or null if no value has been set. If no value is supplied, there is no constrin on the required type
IList<ValidationFailure> | 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.
bool | ExpendAttributeDefaults Ask and set whether attribute defaults defined in a schema are to be expanded or not (by default, fixed and default attribute values are expaned, that is, they are inserted) into the document during validation as if they were present in the instance being validated)
bool | IsLax The validation mode may be either strict or lax. The default is strict; this property is set to indicate that lax validation is required. With strict validation, validation fails if no element declaration can be located for the outermost element. With lax validation, the absence of an element declaration results in the content being considered valid.
bool | UseXsiSchemaLocation This property defines whether the schema processor will recognize, and attempt to dereference, any `xsi:schemaLocation` and `xsi:noNamespaceSchemaLocation` attributes encountered in the instance document. The default value is true.

### Method Summary
void | AddSource(Stream source, Uri baseUri) Add an instance document to the list of documents to be validated.
void | AddSource(Uri uri) Add an instance document to the list of documents to be validated
void | AddSource(XmlReader reader) Add an instance document to the list of documents to be validated
void | AddSource(XdmNode source) Add an instance document to the list of documents to be validated.
void | Close() Close the destination, allowing resources to be released. Saxon calls this method when it has finished writing to the destination
XdmValue | GetParameter(QName name) Get the value that has set for a schema processor (a parameter defined in the schema using the `saxon:param` extension)
void | Run() Run the validation of the supplied source document, optionally writing the validated document to the supplied destination.
void | SetDestination(XmlDestination destination) Supply the destination to hold the validated document. If no destination is supplied, the validated document is discarded.
void | SetInvalidityHandler(IInvalidityHandler inHandler) Set the `InvalidityHandler` to be used when validating instance documents
void | SetParameter(QName name, XdmValue value) Set the value of a schema parameter (a parameter defined in the schema using the `saxon:param` extension)
void | SetSource(Stream source, Uri baseUri) Supply the instance document to be validated in the form of a `Stream`
void | SetSource(Uri uri) Supply the instance document to be validated in the form of a `Uri` reference
void | SetSource(XmlReader reader) Supply the instance document to be validated, in the form of an `XmlReader`.
void | SetSource(XdmNode source) Supply the instance document to be validated in the form of an `XdmNode`.
void | SetValidityReporting(XmlDestination destination) Set the validation reporting feature, which saves the validation errors in an XML file

## Property Detail

### DocumentElementName

public QName DocumentElementName {get; set; }

The name of the required top-level element of the document to be validated (that is, the name of the outermost element of the document). if no value is supplied, there is no constraint on the required type

### DocumentElementTypeName

public QName DocumentElementTypeName {get; set; }

The name of the required type of the top-level element of the document to be validated. QName of the name of the required type of the document element, or null if no value has been set. If no value is supplied, there is no constrin on the required type

### ErrorList

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

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 while using the schema to validate a source document. It is not used to report errors in the schema itself.

### ExpendAttributeDefaults

public bool ExpendAttributeDefaults {get; set; }

Ask and set whether attribute defaults defined in a schema are to be expanded or not (by default, fixed and default attribute values are expaned, that is, they are inserted) into the document during validation as if they were present in the instance being validated)

### IsLax

public bool IsLax {get; set; }

The validation mode may be either strict or lax. The default is strict; this property is set to indicate that lax validation is required. With strict validation, validation fails if no element declaration can be located for the outermost element. With lax validation, the absence of an element declaration results in the content being considered valid.

### UseXsiSchemaLocation

public bool UseXsiSchemaLocation {get; set; }

This property defines whether the schema processor will recognize, and attempt to dereference, any `xsi:schemaLocation` and `xsi:noNamespaceSchemaLocation` attributes encountered in the instance document. The default value is true.

## Method Detail

### AddSource

public void AddSource(Stream source,
Uri baseUri)

Add an instance document to the list of documents to be validated.

Parameters:

`source` - Source document supplied as a `Stream`
`baseUri` - Base URI of the source document

### AddSource

public void AddSource(Uri uri)

Add an instance document to the list of documents to be validated

Parameters:

`uri` - URI of the source document

### AddSource

public void AddSource(XmlReader reader)

Add an instance document to the list of documents to be validated

Parameters:

`reader` - Source document supplied as an `XmlReader`

### AddSource

public void AddSource(XdmNode source)

Add an instance document to the list of documents to be validated.

Parameters:

`source` - Source document supplied as an `XdmNode` value

### Close

public void Close()

Close the destination, allowing resources to be released. Saxon calls this method when it has finished writing to the destination

### GetParameter

public XdmValue GetParameter(QName name)

Get the value that has set for a schema processor (a parameter defined in the schema using the `saxon:param` extension)

Parameters:

`name` - the parameter whose name is required

Returns:

the value that has been set for the parameter, or the EmptySequence if no value has been set

### Run

public void Run()

Run the validation of the supplied source document, optionally writing the validated document to the supplied destination.

### SetDestination

public void SetDestination(XmlDestination destination)

Supply the destination to hold the validated document. If no destination is supplied, the validated document is discarded.

The destination differs from the source in that (a) default values of missing elements and attributes are supplied, and (b) the typed values of elements and attributes are available. However, typed values can only be accessed if the result is represented using the XDM data model, that is, if the destination is supplied as an `XdmDestination`.

Parameters:

`destination` - The destination to hold the validated document.

### SetInvalidityHandler

public void SetInvalidityHandler(IInvalidityHandler inHandler)

Set the `InvalidityHandler` to be used when validating instance documents

Parameters:

`inHandler` - the `InvalidityHandler` to be used

### SetParameter

public void SetParameter(QName name,
XdmValue value)

Set the value of a schema parameter (a parameter defined in the schema using the `saxon:param` extension)

Parameters:

`name` - the name of the schema parameter, as a QName
`value` - the value of the schema parameter, or null to clear a previously set value

### SetSource

public void SetSource(Stream source,
Uri baseUri)

Supply the instance document to be validated in the form of a `Stream`

Parameters:

`source` - A stream containing the XML document to be parsed and validated. This stream will be consumed by the validation process, but it will not be closed after use: that is the responsibility of the caller.
`baseUri` - The base URI to be used for resolving any relative references, for example a reference to an `xsi:schemaLocation`

### SetSource

public void SetSource(Uri uri)

Supply the instance document to be validated in the form of a `Uri` reference

Parameters:

`uri` - URI of the document to be validated

### SetSource

public void SetSource(XmlReader reader)

Supply the instance document to be validated, in the form of an `XmlReader`.

The `XmlReader` is responsible for parsing the document; this method validates it.

Parameters:

`reader` - The `XmlReader` used to read and parse the instance document being validated. This is used as supplied. For conformance, use of a plain `XmlTextReader` is discouraged, because it does not expand entity references. This may cause validation failures.

### SetSource

public void SetSource(XdmNode source)

Supply the instance document to be validated in the form of an `XdmNode`.

The supplied node must be either a document node or an element node. If an element node is supplied, then the subtree rooted at this element is validated as if it were a complete document: that is, it must not only conform to the structure required of that element, but any referential constraints (keyref, IDREF) must be satisfied within that subtree.

Parameters:

`source` - The document or element node at the root of the tree to be validated

### SetValidityReporting

public void SetValidityReporting(XmlDestination destination)

Set the validation reporting feature, which saves the validation errors in an XML file

Parameters:

`destination` - destination where XML will be sent