W3C home > Mailing lists > Public > www-xml-schema-comments@w3.org > January to March 2003

templating in XML schema

From: by way of <erik@gaffle.com>
Date: Wed, 08 Jan 2003 06:27:04 -0700
Message-Id: <5.1.0.14.1.20030108062701.029b3d28@localhost>
To: W3C XML Schema Comments list <www-xml-schema-comments@w3.org>






I want to suggest an addition to the current specification, to make it
easier to create XML representations of related (i.e., similar in a
particular regard) types in schemata:  a system of templates, loosely
based on that of C++.

An example will make clearer the issue I'm addressing.

Say one has the following type definition, intended primarily for use as a
base-type in extensions:

   <xs:complexType name="contentType">
     <xs:sequence>
       <xs:element name="con" type="xs:string" minOccurs="0"
         maxOccurs="unbounded"/>
     </xs:sequence>
   </xs:complexType>

and the following two typical extensions:

   <xs:complexType name="content1Type">
     <xs:complexContent>
       <xs:extension base="contentType">
         <xs:attribute name="id" use="required">
           <xs:simpleType>
	    <xs:restriction base="xs:id">
	      <xs:pattern value="C1[0-9]{8}[a-zA-Z]*"/>
	    </xs:restriction>
	  </xs:simpleType>
	</xs:attribute>
       </xs:extension>
     </xs:complexContent>
   </xs:complexType>

   <xs:complexType name="content2Type">
     <xs:complexContent>
       <xs:extension base="contentType">
         <xs:attribute name="id" use="required">
           <xs:simpleType>
	    <xs:restriction base="xs:id">
	      <xs:pattern value="C2[0-9]{8}[a-zA-Z]*"/>
	    </xs:restriction>
	  </xs:simpleType>
	</xs:attribute>
       </xs:extension>
     </xs:complexContent>
   </xs:complexType>


It seems a shame to require so much extra typing for each extension,
when the only thing that will change with each additional one is the
name of the type and the value of the pattern in the definition of the
attribute.  It would be nice rather to be able to do something like
the following:

   <xs:complexTypeTemplate name="contentTypeTemp">
     <xs:complexType>
       <xs:sequence>
         <xs:element name="con" type="xs:string" minOccurs="0"
           maxOccurs="unbounded"/>
       </xs:sequence>
       <xs:attribute name="id" use="required">
         <xs:simpleType>
           <xs:restriction base="xs:id">
	    <xs:pattern value="{$id}[0-9]{8}[a-zA-Z]*"/>
	  </xs:restriction>
	</xs:simpleType>
       </xs:attribute>
     </xs:complexType>
   </xs:complexTypeTemplate>

   <xs:complexType template="contentTypeTemp" name="content1Type">
     <xs:param name="id" value="C1"/>
   </xs:complexType>

   <xs:complexType template="contentTypeTemp" name="content2Type">
     <xs:param name="id" value="C2"/>
   </xs:complexType>


One could then also extend or restrict templates themselves, or do so on
an instance by instance basis, in individual types based on the templates.

Yours,
Erik Curiel 
Received on Wednesday, 8 January 2003 08:31:16 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Sunday, 6 December 2009 18:13:01 GMT