W3C home > Mailing lists > Public > xmlschema-dev@w3.org > July 2004

Re: Unique and Substitution groups

From: Jeni Tennison <jeni@jenitennison.com>
Date: Tue, 20 Jul 2004 14:45:59 +0100
Message-ID: <362001328.20040720144559@jenitennison.com>
To: Adam van den Hoven <avandenhoven@cucbc.com>
Cc: XML Schema Development <xmlschema-dev@w3.org>

Hi Adam,

Just to add to Mike's reply: what you have to do in this situation is
use unioned paths that select all the directories and files, as

  <xs:key name="paths">
    <xs:selector xpath="directory | file"/>
    <xs:field xpath="@step"/>

Another problem with your current schema is that you've defined this
identity constraint on the <node> element. Identity constraints only
apply to the element on which  you define them -- unlike types, they
aren't inherited via the substitution group hierarchy. You never have
any <node> elements in your document (since they're abstract), so the
key will never come into play. The identity constraints should
probably be defined on the <directory> element instead.

Also, I'm not sure what constraint you actually want to test here.
Currently you're testing that, within one particular <node>, no
*child* <directory> or <file> has the same step as any other. Do you
want to make sure that in the document *as a whole* there aren't any
directories or files with the same value for their step attributes? If
so, then rather than defining the identity constraint on the <node>
element, you should define it on the <directory> element (since that's
your document element) and define the key over all the descendant (not
just children) <directory> and <file> elements:

  <xs:key name="paths">
    <xs:selector xpath=".//directory | .//file"/>
    <xs:field xpath="@step"/>

> In preparing this example, I started getting exceptions on the
> LeafType delcaration. Namely, I'm being told:
>     cos-particle-restrict.2: Forbidden particle restriction:
> 'choice:all,sequence,elt'.
>     derivation-ok-restriction.5.4.2: Error for type 'LeafType'.  The
> particle of the type is not a valid restriction of the particle of the base.
> Both errors refer to the LeafType complexType.

The rules governing legal restrictions are really complicated,
especially when you start factoring in substitution groups and
wildcards. The element particle for <node> is replaced with a choice
between the members of the substitution groups. Xerces seems to be
objecting to the way that choice gets restricted (MSXML is happy with
it). I found that doing:

  <xs:complexType name="LeafType">
      <xs:restriction base="NodeType">
          <xs:element ref="title" minOccurs="0" maxOccurs="unbounded"/>
          <xs:choice minOccurs="0" />
        <xs:attribute name="step" type="xs:NMTOKEN"/>

Fixed the problem. (The minOccurs="0" on the empty <xs:choice> is only
necessary if you want it to work in MSXML as well.)

Alternatively, you could reverse the hierarchy like this:

<xs:complexType name="LeafType">
    <xs:element ref="title" minOccurs="0" maxOccurs="unbounded" />
  <xs:attribute name="step" type="xs:NMTOKEN" />

<xs:complexType name="NodeType">
    <xs:extension base="LeafType">
        <xs:element ref="node" minOccurs="0" maxOccurs="unbounded" />

Finally, another thing I noticed in your schema. You have:

>   <xs:complexType name="Label" id="ComplexType.Label">
>     <xs:simpleContent>
>       <xs:restriction base="Title">
>         <xs:attribute ref="role" fixed="label" use="prohibited"/>
>       </xs:restriction>
>     </xs:simpleContent>
>   </xs:complexType>

The <xs:attribute> here isn't doing what you think it's doing.
use="prohibited" means that, in this restriction, the previously
optional attribute is no longer allowed: it's a mechanism for
excluding attributes that are otherwise inherited when you derive a
type by restriction.

Without the use="prohibited", the <xs:attribute> would mean that if an
element of the type Label had a role attribute, it would have to
have the value 'label', and if it didn't then a role attribute would
be added to it in the PSVI.

But with the use="prohibited", you're saying that the elements of type
Label don't have role attributes at all. Importantly, this means that
you won't get the role attributes added in the PSVI. So the
fixed="label" does nothing here.



Jeni Tennison
Received on Tuesday, 20 July 2004 09:46:04 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:56:05 UTC