Package org.apache.daffodil.api.validation
Daffodil provides a number of built-in validators for use with DataProcessor.withValidation(String, URL)
. For each
built-in validator, the following contains the validator name, a
description, and validator specific properties. The String
parameter
should be the name of the validator. If the URI parameter ends in
.conf or .properties then it is treated as a Properties
file that provides validator properties. Otherwise,
the URI is set to a property with the same name as the validator. If a
validator does not require properties, the URI parameter can be set to
null
or excluded.
- off
-
Description: disable validation
Properties: none
Example:
// explicitly disable validation dataProcessor.withValidation("off")
- daffodil
-
Description: XML schema validation using Daffodil
Properties: none
Example:
// enable XML schema validation using Daffodil dataProcessor.withValidation("daffodil")
- xerces
-
Description: XML Schema validation using Xerces library
Properties:
xerces
- absolute URI to a XSD file
Example:
// enable XML schema validation, setting the "xerces" property to the schema.xsd file dataProcessor.withValidation("xerces", new URL("file:///path/to/schema.xsd"))
- schematron
-
Description: schematron validation using Saxon-HE library
Properties:
schematron
-
absolute URI to a file containing schematron rules. If the URI
ends with
.sch
then the file is treated as a schematron file. Otherwise, it is treated as an XSD file containing embedded schematron rules. schematron.svrl.file
- absolute URI to a file to write the results of schematron validation in SVRL format. This property is not thread safe and will overwrite existing files--it is intended primarily for debugging with single file validation.
Example:
// enable schematron validation, setting the "schematron" property to the schematron.sch file dataProcessor.withValidation("schematron", new URL("file:///path/to/schematron.sch")) // use schematron validation, reading the schematron.properties file to set "schematron" or other schematron properties dataProcessor.withValidation("schematron", new URL("file:///path/to/schematron.properties"))
Custom Validators
Daffodil also supports custom validators. To make a custom validator available to Daffodil, follow these steps:
- Create a custom class that implements the
Validator
interface - Create a custom class that implements the
ValidatorFactory
interface, whosemake
method returns the custom Validator from the previous step - Register the custom ValidatorFactory by creating a
ValidatorFactory
file inMETA-INF/services/
, its contents being the fully qualified name of the custom validator factory - Call the
DataProcessor.withValidation(String, URL)
function, providing the name of the validator and optional URI.
-
ClassDescriptionValidation Handler class to facilitate handling validation errorsImplement this trait to provide custom validation logicImplement this trait and register with SPI to provide runtime discovery of Validator implementationsException to be thrown when initialization of a validator failsException thrown for failed registration of a validatorAccess SPI registered
ValidatorFactory
instances.