net.sf.saxon.s9api
public class SchemaValidator extends Object implements Destination
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. Expansion of defaults can be suppressed by means of the method SchemaValidator.
A SchemaValidator is serially resuable but not thread-safe. That is, it should normally be used in the thread where it is created, but it can be used more than once, to validate multiple input documents.
A SchemaValidator is a Destination, which allows it to receive the output of a query or transformation to be validated.
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.
Constructor Summary | |
---|---|
protected | SchemaValidator(Configuration config) |
Method Summary | |
---|---|
Destination | getDestination()
Get the Destination that will receive the validated document. |
QName | getDocumentElementName()
Get the name of the required top-level element of the document to be validated. |
protected SchemaType | getDocumentElementType()
Get the schema type against which the document element is to be validated |
QName | getDocumentElementTypeName()
Get the name of the required type of the top-level element of the document to be validated. |
ErrorListener | getErrorListener()
Get the ErrorListener being used while validating instance documents |
Receiver | getReceiver(Configuration config) |
boolean | isExpandAttributeDefaults()
Ask whether attribute defaults defined in a schema are to be expanded or not
(by default, fixed and default attribute values are expanded, that is, they are inserted
into the document during validation as if they were present in the instance being validated) |
boolean | isLax()
Ask whether validation is to be in lax mode. |
boolean | isUseXsiSchemaLocation()
Ask whether the schema processor is to take account of any xsi:schemaLocation and
xsi:noNamespaceSchemaLocation attributes encountered while validating an instance document |
void | setDestination(Destination destination)
Set the Destination to receive the validated document. |
void | setDocumentElementName(QName name)
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). |
void | setDocumentElementTypeName(QName name)
Set the name of the required type of the top-level element of the document to be validated.
|
void | setErrorListener(ErrorListener listener)
Set the ErrorListener to be used while validating instance documents. |
void | setExpandAttributeDefaults(boolean expand)
Set whether attribute defaults defined in a schema are to be expanded or not
(by default, fixed and default attribute values are expanded, that is, they are inserted
into the document during validation as if they were present in the instance being validated) |
void | setLax(boolean lax)
The validation mode may be either strict or lax. |
void | setUseXsiSchemaLocation(boolean recognize)
Say whether the schema processor is to take account of any xsi:schemaLocation and
xsi:noNamespaceSchemaLocation attributes encountered while validating an instance document |
void | validate(Source source)
Validate an instance document supplied as a Source object |
Returns: the destination to receive the validated document, or null if none has been supplied
Returns: the name of the required document element, or null if no value has been set.
Returns: the schema type
Returns: the name of the required type of the document element, or null if no value has been set.
Returns: listener The error listener in use. This is notified of all errors detected during the validation episode. Returns null if no user-supplied ErrorListener has been set.
Returns: true if defaults are to be expanded, false if not
Returns: true if validation is to be in lax mode, false if it is to be in strict mode.
Returns: true if these two attributes are to be recognized; false if they are to be ignored. Default is true.
Parameters: destination the destination to receive the validated document
Parameters: name the name of the document element, as a QName; or null to remove a previously-specified value.
Parameters: name the name of the type of the document element, as a QName; or null to remove a previously-specified value. This must be the name of a type in the schema (typically but not necessarily a complex type).
Throws: SaxonApiException if there is no known type with this name
Parameters: listener The error listener to be used. This is notified of all errors detected during the validation episode.
Parameters: expand true if defaults are to be expanded, false if not
Parameters: lax true if validation is to be lax, false if it is to be strict
Parameters: recognize true if these two attributes are to be recognized; false if they are to be ignored. Default is true.
Parameters: source the instance document to be validated. The call getSystemId() applied to this source object must return the base URI used for dereferencing any xsi:schemaLocation or xsi:noNamespaceSchemaLocation attributes
Throws: SaxonApiException if the source document is found to be invalid