OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: example and explanation of substitutionGroup in Schema

[ Lists Home | Date Index | Thread Index ]
  • From: ht@cogsci.ed.ac.uk (Henry S. Thompson)
  • To: "Tolkin, Steve" <Steve.Tolkin@FMR.COM>
  • Date: Sun, 03 Dec 2000 14:37:58 +0000

"Tolkin, Steve" <Steve.Tolkin@FMR.COM> writes:

> Suppose I have a user who has defined many elements.  For various reasons,
> e.g. to hold common attributes, it was decided to enclose each element in a
> common wrapper element.
> Using DTD notation (because it is terser) the content model might look like
> 
> <!ELEMENT wrapper
> ( elem1 
> | elem2 
> | ... 
> | elem999)
> >
> 
> I know I could translate this directly to Schema.  But then adding or
> renaming an element requires changing two places.
> I think that an alternate way of expressing this, maybe, is to use a
> substitutionGroup.
> 
> <element name="dummyElement" abstract="true" type="decimal"
> substitutionGroup="myElement"/>
> 
> <element name="elem1" substitutionGroup="myElement"/>
> <element name="elem2" substitutionGroup="myElement"/>
> ...
> <element name="elem999" substitutionGroup="myElement"/>
> 
> What are the pro's and con's of this?
> One pro that I can see is that adding an element is easier, in that one one
> place in the Schema needs to be changed.

That's the big plus, along with the fact that your schema is much more 
readable (corrections to your slight mis-use of the syntax):

<xs:element name="wrapper">
 <xs:complexType>
  <xs:sequence>
   <xs:element ref="myElementClass"/>
  </xs:sequence>
 </xs:complexType>
</xs:element>

<xs:element name="myElementClass" abstract="true" type="xs:decimal">
 <xs:annotation><xs:documentation>The head of a substitution group for
   all my blah blah elements.</xs:documentation></xs:annotation>
</xs:element>

<xs:element name="elem1" substitionGroup="myElementClass"/>
<xs:element name="elem2" substitionGroup="myElementClass"/>
...
<xs:element name="elem99" substitionGroup="myElementClass"/>

Also (presuming this is what you want!) note that all the members of
the group get the xs:decimal type by default.

For another example, see the XML Schema Primer [1].

ht

[1] http://www.w3.org/TR/xmlschema-0/#SubsGroups
-- 
  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/




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS