W3C home > Mailing lists > Public > xmlschema-dev@w3.org > April 2003

RE: different attribute value sets for the same element ref?

From: Giles Hogben <giles.hogben@jrc.it>
Date: Mon, 14 Apr 2003 15:41:49 +0200
To: "Jeni Tennison" <jeni@jenitennison.com>
Cc: <xmlschema-dev@w3.org>
Message-ID: <GAEKIJGJBJOBBJEFAHMLEEMHCIAA.giles.hogben@jrc.it>

Sorry, I still don't feel this really solves the problem I have.
Perhaps I've misunderstood but I did read the primer extensively to try to
find an answer.
The point is that I need to use the category element many times in my schema
(say 50), each time with a different allowable set of values for name. The
solution you give below does not allow reuse of the category element + name
attribute definition (does it?).

-----Original Message-----
From: Jeni Tennison [mailto:jeni@jenitennison.com]
Sent: Monday, April 14, 2003 3:29 PM
To: Giles Hogben
Subject: Re: different attribute value sets for the same element ref?


Hi Giles,

> Thanks - I am still unsure whether it is correct syntax to create
> this restriction below a reference to an element (and also below a
> reference to an attribute)
>
> Is it?
>
>> I thought about doing it something like this:
>>
>> <xs:element name="home">
>>     <xs:element ref="category">
>>         <xs:attribute ref="name">
>                <xs:simpleType>
>                 <xs:restriction base="xs:token">
>                         <xs:enumeration value="X" />
>                                 <xs:enumeration value="Y" />
>                                 <xs:enumeration value="Z" />
>                 </xs:restriction>
>     </xs:simpleType>
>>         </xs:attribute>
>>     </xs:element>
>> </xs:element>

No, that's not proper XML Schema syntax (sorry I didn't point that out
to you -- I thought you were using a kind of shorthand for brevity).

In XML Schema, each <xs:element> and <xs:attribute> element is either
a declaration or a reference to a declaration elsewhere. Declarations
have a name attribute and can have content to specify the type of the
element/attribute; references have a ref attribute and don't have
content. You're mixing the two up in the above. What you want is
something more like:

<xs:element name="home">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="category">
        <xs:complexType>
          <xs:attribute name="name">
            <xs:simpleType>
              <xs:restriction base="xs:token">
                <xs:enumeration value="X" />
                <xs:enumeration value="Y" />
                <xs:enumeration value="Z" />
              </xs:restriction>
            </xs:simpleType>
          </xs:attribute>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>

If you find this tedious to write (I do!), you could write it using
RELAX NG and then convert it to XML Schema using James Clark's Trang.
The RELAX NG version of the above is a lot closer to your guesses at
syntax, so you might find it easier to get the hang of:

<element name="home">
  <element name="category">
    <attribute name="name">
      <choice>
        <value>X</value>
        <value>Y</value>
        <value>Z</value>
      </choice>
    </attribute>
  </element>
</element>

Otherwise I recommend that you read through the XML Schema Primer or a
book to learn XML Schema syntax.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Monday, 14 April 2003 09:39:24 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:36 GMT