public class SchemaValidatorImpl extends SchemaValidator
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 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 and Description |
---|
SchemaValidatorImpl(Processor processor) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the destination, allowing resources to be released.
|
protected ValidationParams |
convertParams(GlobalParameterSet suppliedParams,
java.util.Collection<GlobalParam> declaredParams) |
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.
|
javax.xml.transform.ErrorListener |
getErrorListener()
Get the ErrorListener being used while validating instance documents
|
InvalidityHandler |
getInvalidityHandler()
Get the InvalidityHandler used when validating instance documents
|
XdmValue |
getParameter(QName name)
Get the value that has been set for a schema parameter (a parameter defined in the schema using
the
saxon:param extension) |
Receiver |
getReceiver(Configuration config)
A SchemaValidator is a Destination (for example, it can act as the destination of a query
or transformation).
|
boolean |
isCollectStatistics()
Ask whether validation statistics are to be collected
|
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 |
reportValidationStatistics(Destination destination)
Report the validation statistics from the most recent validation episode
Does nothing if no validation statistics have been collected.
|
void |
setCollectStatistics(boolean collect)
Say whether validation statistics are to be collected.
|
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(javax.xml.transform.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 |
setInvalidityHandler(InvalidityHandler handler)
Set the InvalidityHandler to be used when validating instance documents
|
void |
setLax(boolean lax)
The validation mode may be either strict or lax.
|
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 |
setThreadCount(int tc) |
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 |
setValidityReporting(Destination destination)
Setup Validation Reporting feature which saves the validation errors in an XML file
|
void |
validate(javax.xml.transform.Source source)
Validate an instance document supplied as a Source object
|
void |
validateMultiple(java.lang.Iterable<javax.xml.transform.Source> sources)
Validate multiple instance documents supplied as a Iterable collection of Source objects
|
asSource
public SchemaValidatorImpl(Processor processor)
public void setLax(boolean lax)
setLax
in class SchemaValidator
lax
- true if validation is to be lax, false if it is to be strictpublic boolean isLax()
isLax
in class SchemaValidator
public void setErrorListener(javax.xml.transform.ErrorListener listener)
setErrorListener
in class SchemaValidator
listener
- The error listener to be used. This is notified of all errors detected during the
validation episode.public javax.xml.transform.ErrorListener getErrorListener()
getErrorListener
in class SchemaValidator
public void setValidityReporting(Destination destination) throws SaxonApiException
setValidityReporting
in class SchemaValidator
destination
- where XML will be sentSaxonApiException
public InvalidityHandler getInvalidityHandler()
getInvalidityHandler
in class SchemaValidator
public void setInvalidityHandler(InvalidityHandler handler)
setInvalidityHandler
in class SchemaValidator
handler
- the InvalidityHandler to be usedpublic void setCollectStatistics(boolean collect)
setCollectStatistics
in class SchemaValidator
collect
- true if validation statistics are to be collected (default is false)public boolean isCollectStatistics()
isCollectStatistics
in class SchemaValidator
public void reportValidationStatistics(Destination destination) throws SaxonApiException
reportValidationStatistics
in class SchemaValidator
destination
- the destination to which the statistics will be written.
The XML format of the destination is not guaranteed to be stable across
Saxon releases.SaxonApiException
- if any error occurs writing the statisticspublic void setUseXsiSchemaLocation(boolean recognize)
setUseXsiSchemaLocation
in class SchemaValidator
recognize
- true if these two attributes are to be recognized; false if they are to
be ignored. Default is true.public boolean isUseXsiSchemaLocation()
isUseXsiSchemaLocation
in class SchemaValidator
public void setDestination(Destination destination)
setDestination
in class SchemaValidator
destination
- the destination to receive the validated documentpublic Destination getDestination()
getDestination
in class SchemaValidator
public void setDocumentElementName(QName name)
setDocumentElementName
in class SchemaValidator
name
- the name of the document element, as a QName; or null to remove a previously-specified
value.public QName getDocumentElementName()
getDocumentElementName
in class SchemaValidator
public void setDocumentElementTypeName(QName name) throws SaxonApiException
setDocumentElementTypeName
in class SchemaValidator
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).SaxonApiException
- if there is no known type with this namepublic QName getDocumentElementTypeName()
getDocumentElementTypeName
in class SchemaValidator
protected SchemaType getDocumentElementType()
getDocumentElementType
in class SchemaValidator
public void setExpandAttributeDefaults(boolean expand)
setExpandAttributeDefaults
in class SchemaValidator
expand
- true if defaults are to be expanded, false if notpublic boolean isExpandAttributeDefaults()
isExpandAttributeDefaults
in class SchemaValidator
public void setParameter(QName name, XdmValue value)
saxon:param
extension)setParameter
in class SchemaValidator
name
- the name of the schema parameter, as a QNamevalue
- the value of the schema parameter, or null to clear a previously set valuepublic XdmValue getParameter(QName name)
saxon:param
extension)getParameter
in class SchemaValidator
name
- the parameter whose name is requiredpublic void setThreadCount(int tc)
public void validateMultiple(java.lang.Iterable<javax.xml.transform.Source> sources) throws SaxonApiException
validateMultiple
in class SchemaValidator
sources
- the Iterable collection of instance documents to be validated. The call getSystemId() applied to
the source objects must return the base URI used for dereferencing any xsi:schemaLocation
or xsi:noNamespaceSchemaLocation attributesSaxonApiException
- if the source document is found to be invalid, or if error conditions
occur that prevented validation from taking place (such as failure to read or parse the input
document). The wrapped exception acting as the cause of the SaxonApiException can be used to
distinguish these failure conditions.public void validate(javax.xml.transform.Source source) throws SaxonApiException
validate
in class SchemaValidator
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 attributesSaxonApiException
- if the source document is found to be invalid, or if error conditions
occur that prevented validation from taking place (such as failure to read or parse the input
document). The wrapped exception acting as the cause of the SaxonApiException can be used to
distinguish these failure conditions.protected ValidationParams convertParams(GlobalParameterSet suppliedParams, java.util.Collection<GlobalParam> declaredParams) throws XPathException
XPathException
public Receiver getReceiver(Configuration config) throws SaxonApiException
getReceiver
in interface Destination
getReceiver
in class SchemaValidator
config
- the Saxon ConfigurationSaxonApiException
- if a failure occurspublic void close() throws SaxonApiException
close
in interface Destination
close
in class SchemaValidator
SaxonApiException
- if any failure occursCopyright (c) 2004-2018 Saxonica Limited. All rights reserved.