More Schematron Features
(Page 1 of 5 )
In my last two articles, I covered the basics of Schematron—enough of it to create a basic schema with assertions, rules and patterns. However, there is more to Schematron than was covered in those articles, and some of Schematron's other features are very useful and worth mentioning. In this article, we'll take a look at more of Schematron's features, delving deeper into the Schematron schema language.
Namespaces
As a modern schema language, Schematron, of course, provides support for namespaces. Consider a document like this:
<ds:articles xmlns:ds="http://developershed.com">
<ds:article>
<ds:name>Using Schematron</ds:name>
</ds:article>
<ds:article>
<ds:name>More Schematron</ds:name>
</ds:article>
</ds:articles>
In order for patterns to match properly, and for Schematron to operate, namespaces need to be declared in the schema. This is very simple to do, and is done using the ns element. The ns element must be declared as a child of the schema element. It has two attributes: prefix and uri. These correspond, of course, to the namespace prefix and the namespace URI. In order to declare the namespace used above, the following XML would be used:
<ns prefix="ds" uri="http://developershed.com"/>
Now the schema will work properly with the document:
<assert test="ds:name">An article must have a name.</assert>
Next: More on assertions >>
More XML Articles
More By Peyton McCullough