|Schematron Usage and Features||
Schematron is an assertion-based schema language. Data constraints are expressed by making assertions (using XPath) about what relationships and patterns should hold true in the data.
Example: The following XML instance document contains a classification attribute on the <Document> element and on the <Para> element:
Schematron can be used to assert:
The first assertion is a co-constraint between the values of two attributes. A co-constraint can apply to any number of dependencies between XML structure components (elements and attributes) as well as between values. A co-constraint may be within an XML document or across multiple XML documents.
The second assertion is a cardinality check. In the above example, the text in the <Para> element must not contain any values that are in a list of restricted keywords. The keywords may be obtained dynamically from another file.
In general, cardinality constraints are constraints on the occurrence of data, elements, or attributes. The cardinality constraints may apply over the entire document or to portions of the document.
The above two uses of Schematron involve examination or comparison of data. A third category of Schematron usage involves validating the data by algorithmic processing of the data.
Example: The following XML instance document contains election results. To be a valid document, the candidate election results must total 100%.
Schematron can be used to assert that the values of the <Candidate> elements must total 100 percent.
Use Schematron to express data constraints:
Additional Schematron Features. Schematron allows the schema author to write descriptive error messages, which can result in more understandable error messages. Schematron also can dynamically obtain data from external files. In the second assertion above, this allows the list of prohibited keywords to be in a separate file.