templating in XML schema

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 Monday, 6 January 2003 18:07:44 UTC