Restrictions

With the exception of constraints expressed by the RELAX NG schema for RELAX NG and those which are part of the simplification itself, RELAX NG defines all the restrictions on schema structures as they apply to the simplified version. Most of them are obvious and easy to understand.

Constraints on Attributes

RELAX NG’s constraints match the constraints on attributes defined by the XML 1.0 recommendation:

  • Attributes can’t contain other attributes; attribute patterns can’t have another attribute pattern in their descendants.

  • Attributes can’t contain elements; attribute patterns can’t have a ref pattern in their descendants.

  • Attributes can’t be duplicated; an attribute may not be found in a oneOrMore pattern with a combination by group or interleave. Furthermore, if attribute patterns are combined in a group or interleave pattern, their name classes must not overlap: they can’t have any name that belongs to both name classes.

  • Attributes that have an infinite name class (anyName or nsName) must be enclosed in a oneOrMore pattern. In other words, you can’t specify only one or a certain number of occurrences of these attributes. They can have only text as their model (in other words, data patterns are forbidden here).

Let’s explore schemas that may look valid at a quick glance but are going to collide with these restrictions.

Bad example: attribute content model

This schema states that any content model can be accepted in the bar attribute:

 anything = (element * { anything } | attribute ...

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.