Validation Processor
1. Rationale
The validation processor can be inserted in a pipeline to validatate data against a
specified schema. The current implementation supports W3C Schema and Relax
NG.
The validator functions in two distinct mode. The decorating mode adds
attribute to the document where errors occur. The non-decorating mode throws
a org.orbeon.oxf.common.ValidationException if the data doesn't
conform to the schema.
2. Usage
Processor Name |
oxf:validation |
config input |
The configuration of this validator. |
schema input |
The schema (W3C Schema or Relax NG). |
data input |
The document to validate. |
data output |
This output mirrors the data input.
|
2.1 Config Input
The configuration input selects the mode of the validator. The validator can
either be in the decorating mode or the non-decorating mode. The
decorating element contains a boolean (true or
false) indicating if the validator is decorating or not. The
following example shows a configuration for a decorating validator.
<config> <decorate>true</decorate>
</config>
2.2 Schema Input
The validation processor's schema input contains a
supported XML schema (W3C or Relax NG). The schema type
is automatically recognized. The following example
shows a simple Relax NG schema for an arbitrary address book.
<element name="addressBook"> <zeroOrMore> <element name="card"> <element name="name"> <attribute name="age"> </attribute> <text/>
</element> <element name="email"> </element> </element> </zeroOrMore> </element>
For more information about Relax NG syntax, read the
Relax NG specification and
Relax NG tutorial. The
W3C Schema Primer
provides a good introduction to the language.
2.3 Data Input
The data input contains the xml data to be
validated. The following document is valid against the address book
schema defined above.
<addressBook> <card> <name age="24">John Smith</name>
<email>js@example.com</email>
</card> <card> <name age="42">Fred Bloggs</name>
<email>fb@example.net</email>
</card> </addressBook>
2.4 Data Output
If the input data is valid against the specified schema, this output mirrors
the input data, i.e. the validation processor is invisible in the pipeline.
However, when validation errors occur, a ValidationException is
thrown and the pipeline processing is interrupted if the validator is in the
non-decorating mode. When in decorating mode, the validator
annotates the output document in the following way:
For each validation error, the validator inserts an additional element after
the error-causing element. This element is in the
http://orbeon.org/oxf/xml/validation namespace URI and contains the
following information:
- The message of the validator
- The system ID of the document, if available
- The location (line and column) within the document, if available.
For example, the following element could be generated:
<v:error message="Error bad character content for element near month (schema: oxf:/date.rng)" system-id="oxf:/date.xml" line="5" column="10" xmlns:v="http://orbeon.org/oxf/xml/validation"/>