Re: empty complexTypes.

An empty complexType is allowed.  And it is useful -- I've used it in a
schema that I wrote where the existing DTD and XML format already required
elements with no content.

I'll go through each of your three definitions of complexType content.

> "Content: (annotation? , (simpleContent | complexContent | ((group | all
|
> choice | sequence)? , ((attribute | attributeGroup)* , anyAttribute?))))"
>
> This looks like there has to be a simpleContent, complexContent, or one
of
> the particles followed by some attribute declarations.

An empty complexType corresponds to the third option.  "(group | all |
choice | sequence)?" - the "?" means zero or one of these, so zero.
"(attribute | attributeGroup)*" - the "*" means zero or more, so zero.
"anyAttribute?" -  zero or one so zero.  Thus this entire third option
becomes empty, and in turn the whole content is empty.

> The complexTypeModel complexType in the Schema for Schemas shows this:
> <schema segment deleted, see below>
> The minOccurs on the choice, element refs, and sequence default to 1,
don't
> they?

The minOccurs do default to 1.  For the choice, choose the third option,
the sequence, and you need exactly one of these.  Which is zero or one
typeDefParticle (because its minOccurs is zero) followed by exactly one
attrDecls, because of the defaults of minOccurs and maxOccurs to 1.  Choose
zero typeDefParticle groups followed by one attrDecl group.  This group is
a sequence that starts with a choice (which has a minOccurs of zero and can
thus be ignored) followed by an anyAttribute element which has a minOccurs
of zero and can thus be ignored as well.  This means that the attrDecl can
be empty and thus the whole complexTypeModel can be empty.

> Lastly, the DTD for Schemas shows this:
>
> <!ELEMENT %complexType; ((%annotation;)?,
>                          (%simpleContent;|%complexContent;|
>                           %particleAndAttrs;))>

Similarly, the %annotation can be empty (zero or one because of the "?").
The choice of the next three entities can be the %particleAndAttrs, which
is defined as "((%mgs; | %group;)?, %attrDecls;)".  The choice can be empty
(again zero or one because of the "?"), meaning that the %attrDecls is the
entire %particleAndAttrs and thus the entire %complexType.  %attrDecls is
in turn defined as "((%attribute;| %attributeGroup;)*,(%anyAttribute;)?)",
where the choice can be empty (zero or more, this time a "*"), and the
%anyAttribute can be missing (again the "?"), thus the %attrDecls can be
empty and thus the entire %complexType can be empty.



"Jason Diamond" <jason@injektilo.org>@w3.org on 12/12/2000 06:20:26 PM

Sent by:  xmlschema-dev-request@w3.org


To:   <xmlschema-dev@w3.org>
cc:
Subject:  empty complexTypes.



Hi.

4.3.3 of the Structures CR says:

"Careful consideration of the above concrete syntax reveals that a type
definition need consist of no more than a name, i.e. that <complexType
name="anyThing"/> is allowed. The result is however not of much use, as it
will have empty {content type} and no allowed attributes."

My careful consideration of the syntax revealed something different,
though.

"Content: (annotation? , (simpleContent | complexContent | ((group | all |
choice | sequence)? , ((attribute | attributeGroup)* , anyAttribute?))))"

This looks like there has to be a simpleContent, complexContent, or one of
the particles followed by some attribute declarations.

The complexTypeModel complexType in the Schema for Schemas shows this:

 <group name="complexTypeModel">
  <choice>
      <element ref="simpleContent"/>
      <element ref="complexContent"/>
      <sequence>
       <annotation>
        <documentation xml:lang="en">
   This branch is short for
   &lt;complexContent>
   &lt;restriction base="anyType">
   ...
   &lt;/restriction>
   &lt;/complexContent></documentation>
       </annotation>
       <group ref="typeDefParticle" minOccurs="0"/>
       <group ref="attrDecls"/>
      </sequence>
  </choice>
 </group>

The minOccurs on the choice, element refs, and sequence default to 1, don't
they?

Lastly, the DTD for Schemas shows this:

<!ELEMENT %complexType; ((%annotation;)?,
                         (%simpleContent;|%complexContent;|
                          %particleAndAttrs;))>

Am I reading these correctly? Since an empty complexType is essentially
worthless, I don't see any value in allowing it. Was it removed from the
schemas but accidentally left in the text?

Thanks,
Jason.

Received on Wednesday, 13 December 2000 00:26:16 UTC