RE: Reg. <all> model group extension

Well, the schema spec is not easy to read: it needs a lot of study to
understand the language it uses. And indeed, it seems my explanation in my
previous email was wrong! Let's take this rule:

[Definition:]  For a particle (call it E, for extension) to be a valid
extension of another particle (call it B, for base)  one of the following
must be true:
1 They are the same particle.
2 E's {min occurs}={max occurs}=1 and its {term} is a sequence group whose
{particles}' first member is a particle all of whose properties,
recursively, are identical to those of B, with the exception of {annotation}
properties.

First you need to understand what a particle is. Loosely, it's anything that
appears in a content model but in practice we're only concerned here with
group-level particles (not leaf particles, which are either element
particles or wildcards). A group-level particle is technically referred to
as a "model group", and it has a term which is either a choice group, a
sequence group, or an all group. 

The theory here is that we build the schema components (such as particles)
from the source XSD, and then test whether the components we have built are
valid. (In practice, the processor will usually do these tests while
building the components, and may not even have the capability to build
invalid components). So we first have to see what the rules are for
constructing a complex type component by extension. These are given under
Complex Type Definition with complex content Schema Component in section
3.4.2. Look for the rules for the {content type} property. For both your
complex types, rule 2.2 applies, which means that the effective content is
the particle corresponding to the <all> element; and then rule 3.2.3
applies, which means that the {content type} of the derived type is
effectively the model group:

<sequence>
        <all>
            <element name="a1" type="string"/>
            <element name="a2" type="string"/>
        </all>
        <all>
             <element name="a3" type="string"/>
        </all>
</sequence>

Now there's a rule in 3.8.6, "Schema Component Constraint: All Group
Limited", which determines whether this model group is actually valid, and
it turns out that it isn't.

The rule says:

When a model group has {compositor} all, then all of the following must be
true:
1 It appears only as the value of one or both of the following properties:
1.1 the {model group} property of a model group definition.
1.2 the {term} property of a particle with {max occurs}=1 which is part of a
pair which constitutes the {content type} of a complex type definition.
2 The {max occurs} of all the particles in the {particles} of the group must
be 0 or 1.

Now here we have two model groups with compositor "all" that appear as part
of a model group with compositor "sequence", which doesn't satisfy either
1.1 or 1.2 (the sequence is not a "model group definition", you only get a
"model group definition" from a <group> element in the schema document.). So
this extended model group isn't valid and therefore the schema isn't valid.

I mentioned the rule Schema Component Constraint: Particle Valid (Extension)
but actually we don't get this far. If we did get this far, the rule would
test whether

<sequence>
        <all>
            <element name="a1" type="string"/>
            <element name="a2" type="string"/>
        </all>
        <all>
             <element name="a3" type="string"/>
        </all>
</sequence>

was a valid extension of 

<all>
      <element name="a1" type="string"/>
      <element name="a2" type="string"/>
</all>

and as it happens, if it got past the rule at 3.8.6, then it would be.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

Received on Monday, 30 November 2009 16:36:12 UTC