Schematron

Rick Jelliffe's Schematron is a radically different approach to schema languages. Whereas other schema languages are conservative (everything not permitted is forbidden), Schematron is liberal (everything not forbidden is permitted). A Schematron schema makes assertions about the content of the document. If all assertions are true, the document is valid. Since the assertions are written in XPath, Schematron can state things that no other schema language can. Here are some examples.

  • The entire document contains exactly ten paragraph elements (which may be nested inside each other).

  • Every FirstName element is followed by a LastName element, regardless of the parent element.

  • If the CPU attribute of a Machine element has the value Sparc , the value of the OS attribute must be either Solaris or Linux .

Key features of Schematron include the following:

  • The ability to compare arbitrary nodes in the document (not limited to parentchild structures)

  • Namespace awareness

  • The ability to validate text, processing instructions, and even comments (not limited to elements and attributes)

  • Customizable error messages

Schematron is most appropriate when:

  • You need to state constraints that are simply not expressible in DTDs, the W3C XML Schema Language, or RELAX NG.

  • Constraints focus on the XML structure of a document.

  • You need to verify co-occurrence constraints; for example, every element that contains a Price child element must have an SKU attribute.

  • You need to verify exclusions such as XHTML's requirement that no a element can contain another a element, not just as a child but as a descendant.

  • You want to verify a few constraints without specifying every aspect of the markup.

  • You want to allow unanticipated developments in the markup.

Schematron is least appropriate when:

  • Validation is concerned with the structure of text in element content and attribute values.

  • Data typing is needed.

I don't know that I would ever pick Schematron as the sole validation layer for documents. Writing a complete Schematron schema that's equivalent to even a simple DTD is very tiresome. Used in this fashion, Schematron would be far and away the most verbose and difficult of the various schema languages. However, Schematron is not normally used in this way. Instead, it is used to attach additional constraints that are impossible to state in the other languages. It is applied as an extra validation step after a document has already been validated against a DTD or some other schema. In particular, it's often used to add co-occurrence and exclusion constraints to schemas in languages such as RELAX NG and the W3C XML Schema Language that don't have them. Some tools (e.g., the Topologi Schematron Validator) will even recognize Schematron schemas hidden inside annotations in a schema written in a different language.



Effective XML. 50 Specific Ways to Improve Your XML
Effective XML: 50 Specific Ways to Improve Your XML
ISBN: 0321150406
EAN: 2147483647
Year: 2002
Pages: 144

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net