Other Options

What if you really need a feature that’s missing in RELAX NG to create building blocks? What if, for instance, you need to reuse a name class or a datatype parameter defined once and only once in multiple locations of a schema?

If this were an absolute requirement, which isn’t often the case, you would have to use non-RELAX NG tools or features. RELAX NG has an advantage over DTDs or W3C XML Schema in that there are two possible syntaxes, leaving the option to work with either XML mechanisms with the XML syntax or plaintext tools with the compact syntax.

There is no limit to the tools to produce our result, but let’s set up a possible use case and some examples of implementations.

A Possible Use Case

Let’s just say you want to specify the set of possible characters in your documents and that you want to implement this rule in your RELAX NG schemas. The pattern you might have in mind to perform this restriction could be the one that’s an example in Chapter 9. It’s not very complex, but not very simple either:

 pattern = "[\p{IsBasicLatin}\p{IsLatin-1Supplement}]*"

Of course, you might want to easily update it if you had to. You wouldn’t want to have to copy it in each datatype definition, and you might want to use this pattern in different contexts over different datatypes and eventually combine it with other parameters.

XML Tools

XML parsed entities (internal or external and in the internal DTD or in an external DTD) may be used in the above case. Using internal entities ...

Get RELAX NG now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.