net.sf.saxon.s9api
Class SchemaValidator
java.lang.Object
net.sf.saxon.s9api.SchemaValidator
- Destination
public class SchemaValidator
extends java.lang.Object
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. Expansion of defaults can be suppressed by means of the method
setExpandAttributeDefaults(boolean)
.
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.
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) - Return a Receiver.
|
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.
|
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 | validate(Source source) - Validate an instance document supplied as a Source object
|
getDestination
public Destination getDestination()
Get the Destination that will receive the validated document. Return null if no destination
has been set.
- the destination to receive the validated document, or null if none has been supplied
getDocumentElementName
public QName getDocumentElementName()
Get the name of the required top-level element of the document to be validated.
- the name of the required document element, or null if no value has been set.
getDocumentElementType
protected SchemaType getDocumentElementType()
Get the schema type against which the document element is to be validated
getDocumentElementTypeName
public QName getDocumentElementTypeName()
Get the name of the required type of the top-level element of the document to be validated.
- the name of the required type of the document element, or null if no value has been set.
getErrorListener
public ErrorListener getErrorListener()
Get the ErrorListener being used while validating instance documents
- 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.
getReceiver
public Receiver getReceiver(Configuration config)
throws SaxonApiException
Return a Receiver. Saxon calls this method to obtain a Receiver, to which it then sends
a sequence of events representing the content of an XML document.
- getReceiver in interface Destination
config
- The Saxon configuration. This is supplied so that the destination can
use information from the configuration (for example, a reference to the name pool)
to construct or configure the returned Receiver.
- the Receiver to which events are to be sent.
isExpandAttributeDefaults
public 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)
- true if defaults are to be expanded, false if not
isLax
public boolean isLax()
Ask whether validation is to be in lax mode.
- true if validation is to be in lax mode, false if it is to be in strict mode.
setDestination
public void setDestination(Destination destination)
Set the Destination to receive the validated document. If no destination is supplied, the
validated document is discarded.
destination
- the destination to receive the validated document
setDocumentElementName
public 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). If no value is supplied, there is no constraint
on the required element name
name
- the name of the document element, as a QName; or null to remove a previously-specified
value.
setDocumentElementTypeName
public void setDocumentElementTypeName(QName name)
throws SaxonApiException
Set the name of the required type of the top-level element of the document to be validated.
If no value is supplied, there is no constraint on the required type
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).
setErrorListener
public void setErrorListener(ErrorListener listener)
Set the ErrorListener to be used while validating instance documents.
listener
- The error listener to be used. This is notified of all errors detected during the
validation episode.
setExpandAttributeDefaults
public 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)
expand
- true if defaults are to be expanded, false if not
setLax
public void setLax(boolean lax)
The validation mode may be either strict or lax. The default is strict; this method may be called
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.
lax
- true if validation is to be lax, false if it is to be strict
validate
public void validate(Source source)
throws SaxonApiException
Validate an instance document supplied as a Source object
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