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: Tue, 15 Apr 2003 09:17:58 +0200
To: "Jeni Tennison" <jeni@jenitennison.com>
Cc: <xmlschema-dev@w3.org>
Message-ID: <GAEKIJGJBJOBBJEFAHMLEEMNCIAA.giles.hogben@jrc.it>

So is there no alternative but to recreate a new category element for each
of the 50 instances?

Thanks for the help


-----Original Message-----
From: Giles Hogben [mailto:giles.hogben@jrc.it]
Sent: Monday, April 14, 2003 3:42 PM
To: Jeni Tennison
Cc: xmlschema-dev@w3.org
Subject: RE: different attribute value sets for the same element ref?

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:element name="category">
          <xs:attribute name="name">
              <xs:restriction base="xs:token">
                <xs:enumeration value="X" />
                <xs:enumeration value="Y" />
                <xs:enumeration value="Z" />

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">

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



Jeni Tennison
Received on Tuesday, 15 April 2003 03:15:42 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:15:10 UTC