ZVON > Tutorials > XML Schema and Relax NG Tutorial
Index
Contents > Restrictions

Restrictions

Restriction of a sequence

The Schema declares type "AAA", which can contain up to two sequences of "x" and "y" elements. Then we declare the type "BBB", which is a restriction of the type "AAA" and contain only one x-y sequence. Schema Component Constraint: Particle Derivation OK (All:All,Sequence:Sequence - Recurse) .

...
Restriction of a choice

The Schema declares type "AAA", which can contain up to two choices from "x" or "y" elements. Then we declare the type "BBB", which is a restriction of the type "AAA" and contain only one x-y choice. Schema Component Constraint: Particle Derivation OK (Choice:Choice -- RecurseLax) .

...
Error in restriction - non-matching types

When restrictions are made, the types must be mapped correctly. Roughly said, we cannot declare element "x" to be a string and then declare it as an "integer" in the restriction. Schema Component Constraint: Particle Derivation OK (All:All,Sequence:Sequence - Recurse), 2. .

...
Error in restriction - maxOccurs

The "maxOccurs" of the type derived by a restriction cannot be higher than the "maxOccurs" attribute of the original type (from which it is restricted). Schema Component Constraint: Particle Derivation OK (All:All,Sequence:Sequence - Recurse), 1. .

...
Error in restriction - namespaces in wildcards

The restriction is valid, because the namespaces "http://foo http://bar" are in the original set of the namespaces "http://foo http://bar http://baz". Schema Component Constraint: Particle Derivation OK (Any:Any - NSSubset) .

The restriction is not valid, because the namespace "http://xxx" is not in the original set of the namespaces "http://foo http://bar http://baz". Schema Component Constraint: Particle Derivation OK (Any:Any - NSSubset) .

Relax NG does not provide such complex derivations (correct me, if I am wrong), but we can very easily use the rules below.

...
"Sequence" from "all"

We can "change" the "all" type to "sequence". Schema Component Constraint: Particle Derivation OK (Sequence:All - RecurseUnordered)

We can "change" the "all" type to "sequence". We can define the sequence reordered. Schema Component Constraint: Particle Derivation OK (Sequence:All - RecurseUnordered)

When we derive "sequence" from "all", we cannot map each element from the "all" group to more than one element from the "sequence" group. Schema Component Constraint: Particle Derivation OK (Sequence:All - RecurseUnordered), 2.1 . In our example, we want to have two "x" elements in the sequence and that's not allowed.

...
"Sequence" from "choice"

We can "change" the "choice" type to "sequence". However, we must satisfy the conditions for occurrence range. Roughly, the length of the original type must be greater than of the derived one. Schema Component Constraint: Particle Derivation OK (Sequence:Choice - MapAndSum)

The schema is not correct, because: the "choice" results into one element, the "maxOccurs" attribute of the "choice" element is 1 (total is 1x1 = 1); the "sequence" results into two elements, the "maxOccurs" attribute of the "sequence" element is 1 (total is 2x1 = 2). And 1 is not greater or equal to 2. In other words, the restricted type is "longer" than the original and that is not allowed. I hope my explanation is OK ...

...
Element from any

Type "AAA" allows one arbitrary element from any namespace. We declare type "BBB", which is a restriction of the type "AAA" and this restriction will allow only element "x" from the target namespace. The target namespace is null here. Schema Component Constraint: Particle Derivation OK (Elt:Any - NSCompat) .

The restriction is not valid, because the occurrence range of element "x" (in the derived type) is higher than of the wildcard (represented by "xsd:any") in the original type. Schema Component Constraint: Particle Derivation OK (Elt:Any - NSCompat), 2 .

...