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 |
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 |
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 |
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 |
void | SetParameter(QName name, XdmValue value)
Set the value of a schema parameter (a parameter defined in the schema using the |
void | SetSource(Stream source, Uri baseUri)
Supply the instance document to be validated in the form of a |
void | SetSource(Uri uri)
Supply the instance document to be validated in the form of a |
void | SetSource(XmlReader reader)
Supply the instance document to be validated, in the form of an |
void | SetSource(XdmNode source)
Supply the instance document to be validated in the form of an |
void | SetValidityReporting(XmlDestination destination) Set the validation reporting feature, which saves the validation errors in an XML file |
Property Detail
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
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
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 while using the schema to validate a source document. It is not used to report errors in the schema itself.
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)
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.
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 Detail
AddSource
Add an instance document to the list of documents to be validated
Parameters:
uri
- URI of the source documentAddSource
Add an instance document to the list of documents to be validated
Parameters:
reader
- Source document supplied as an XmlReader
AddSource
Add an instance document to the list of documents to be validated.
Parameters:
source
- Source document supplied as an XdmNode
valueClose
Close the destination, allowing resources to be released. Saxon calls this method when it has finished writing to the destination
GetParameter
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 requiredReturns:
Run
Run the validation of the supplied source document, optionally writing the validated document to the supplied destination.
SetDestination
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
Set the InvalidityHandler
to be used when validating instance documents
Parameters:
inHandler
- the InvalidityHandler
to be usedSetParameter
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 QNamevalue
- the value of the schema parameter, or null to clear a previously set valueSetSource
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
Supply the instance document to be validated in the form of a Uri
reference
Parameters:
uri
- URI of the document to be validatedSetSource
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
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 validatedSetValidityReporting
Set the validation reporting feature, which saves the validation errors in an XML file
Parameters:
destination
- destination where XML will be sent
Add an instance document to the list of documents to be validated.
Parameters:
source
- Source document supplied as aStream
baseUri
- Base URI of the source document