Schema Alternatives

Just as DTDs are not the only way to create a schema for use with XML, there are also alternatives to XML Schemas. The two most popular alternatives to XML Schemas include RELAX NG and Schematron.

RELAX NG

The most promising schema alternative currently being developed is the RELAX NG standard, which is being sponsored by the Organization for the Advancement of Structured Information Standards (OASIS). The RELAX NG standard is the result of a positive reception among developers to both TREX and RELAX, two older schema alternatives, and the desire to see features of each incorporated into the other, culminating in RELAX NG, a merger of TREX and RELAX.

OASIS has released a formal standard for RELAX NG, which can be found at

http://www.oasis-open.org/committees/relax-ng/spec-20011203.html

Because OASIS is a very powerful, vendor-neutral standards organization, RELAX NG is a very viable alternative to XML Schema.

RELAX NG combines the features of TREX and RELAX into one syntax, and it is also XML based. The goal of RELAX NG is to provide a simple, easy-to-learn syntax for describing grammars that are not necessarily hampered by backward compatibility and complexity, as is the case with XML Schemas.

Schematron

Schematron was developed by Rick Jelliffe, and is not so much an alternative to XML Schemas as it is a supplemental technology. Jelliffe has described Schematron as a feather duster that reaches into the corners that the XML Schemas vacuum cleaner can't reach. Schematron is supported via a Web site located at

http://www.ascc.net/xml/schematron

What makes Schematron different from the other schema alternatives is that Schematron is not grammar based. Instead, it is rules based, and therefore provides a level of validity checking simply not possible with XML Schemas.

For example, Schematron allows you to check the content of elements and attributes, and then check for dependencies based on those results. Schematron also provides you with a mechanism for returning “plain English” error messages that are easily understood.

For example, let's say you had the following XML instance:

<employee SSN="331001234">Jane Doe</employee> 

Schematron would allow you to check to make sure that the <employee> element had the “SSN” attribute, and it would allow you to count the digits in the “SSN” attribute, as well as to check to make sure that a name was included for the element content. And if there was a problem, using Schematron, you could specify an error message such as

“Social Security numbers should be exactly 9 digits”

Schematron is very flexible, and, in fact, it can be used not only with XML Schemas, but also with RELAX Modules and TREX Grammars!

As if that weren't enough, Schematron is also very simple. There are only six basic elements in Schematron, and the technology is built using XSLT and XPath. So, if you already know XPath and XSLT, Schematron can be learned very quickly.

Schematron works by using XPath to specify the location and conditions that are being checked, and it uses XSLT to perform the manipulation of the Schematron Schema and the application of the Schematron Schema to your instance documents.

Another advantage of Schematron is that because it is based on core XML technologies, Schematron Schemas can actually be nested directly within XML Schema–based schemas, using an <annotation> and the <appinfo> elements.

Schematron is an excellent choice for a supplementary technology to provide a finer level of validation than possible with XML Schemas.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.8.222