W3C home > Mailing lists > Public > www-xml-schema-comments@w3.org > April to June 2000

Re: Using derivedBy to define lists of permitted attribute values

From: Henry S. Thompson <ht@cogsci.ed.ac.uk>
Date: 13 Apr 2000 14:24:46 +0100
To: "Martin Bryan" <mtbryan@sgml.u-net.com>
Cc: <www-xml-schema-comments@w3.org>
Message-ID: <f5bzoqy5e1t.fsf@cogsci.ed.ac.uk>
"Martin Bryan" <mtbryan@sgml.u-net.com> writes:

> I am trying to work out whether or not the derivedBy facet can be used to identify an element that contains a list of permitted values for an attribute. It seems to me to be a useful feature but I cannot see how it would work as the element referenced by derivedBy has, according to the Primer at least, and by implication from Part 2, to be in the instance and not in the schema. I was thinking about something along the following lines:
> 
> <xsd:attribute name=”Code” base=”xsd:string”>
>  <xsd:simpleType name=”CodeList” base=”xsd:string” derivedBy=”xsd:list”/>
> </xsd:attribute>
> <MyCodeList xsi:type="CodeList">AB1 CD2 EF3</MyCodeList> 


Confusion of levels/locations/facilities, I guess.

If you want to constrain element content, use an element declaration:

<xs:schema xmlns='[URI:martinbryan]' targetNamespace='[URI:martinbryan]'
           xmlns:xs='http://www.w3.org/1999/XMLSchema'>
 <xs:simpleType name='CodeList' base='xs:string' derivedBy='list'/>

 <xs:element name='MyCodeList' type='CodeList'/>
</xs:schema>

<docroot xmlns='[URI:martinbryan]'>
 ...
 <MyCodeList>AB1 CD2 EF3</MyCodeList>
</docroot>

The <docroot> instance above is, as far as we can tell from the
fragments given, schema-valid per the schema corresponding to the
schema document above it.

If you want to constrain an element beyond its schema declaration in
an instance, use xsi:type:

<xs:schema xmlns='[URI:martinbryan]' targetNamespace='[URI:martinbryan]'
           xmlns:xs='http://www.w3.org/1999/XMLSchema'>
 <xs:simpleType name='CodeList' base='xs:string' derivedBy='list'/>

 <xs:element name='MyContainer' content='textOnly'/>
</xs:schema>

<docroot xmlns='[URI:martinbryan]'
         xmlns:xsi='http://www.w3.org/1999/XMLSchema-instance'>
 ...
 <MyContainer xsi:type='CodeList'>AB1 CD2 EF3</MyCodeList>
</docroot>

Again, the <docroot> instance above is, as far as we can tell from the
fragments given, schema-valid per the schema corresponding to the
schema document above it.

Neither of these examples define the restricted element type in the
instance.  To do that you have to play games with what amounts to an
internal subset:

schema3.xsd:
<xs:schema xmlns='[URI:martinbryan]' targetNamespace='[URI:martinbryan]'
           xmlns:xs='http://www.w3.org/1999/XMLSchema'>

 <xs:element name='MyContainer' content='textOnly'/>
</xs:schema>

<container xmlns='[URI:martinbryan]'
         xmlns:xsi='http://www.w3.org/1999/XMLSchema-instance'
         xmlns:xs='http://www.w3.org/1999/XMLSchema'
         xsi:schemaLocation='[URI:martinbryan] #xpointer(*/xs:schema)'>
 <xs:schema  targetNamespace='[URI:martinbryan]'>
  <include 'schema3.xsd'/>
  <xs:simpleType name='CodeList' base='xs:string' derivedBy='list'/>
 </xs:schema>
 <docroot>
   ...
   <MyContainer xsi:type='CodeList'>AB1 CD2 EF3</MyCodeList>
 </docroot>
</container>

Hope this helps

ht
-- 
  Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
          W3C Fellow 1999--2001, part-time member of W3C Team
     2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
	    Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
		     URL: http://www.ltg.ed.ac.uk/~ht/
Received on Thursday, 13 April 2000 09:24:50 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:49:52 UTC