W3C home > Mailing lists > Public > xmlschema-dev@w3.org > February 2001

Re: [Moderator Action] Anonymous Types with same name problem

From: Henry S. Thompson <ht@cogsci.ed.ac.uk>
Date: 02 Feb 2001 12:22:12 +0000
To: John Britton <johnb@peakaudio.com>
Cc: "'xmlschema-dev@w3.org'" <xmlschema-dev@w3.org>
Message-ID: <f5bvgqt6zrf.fsf@cogsci.ed.ac.uk>
John Britton <johnb@peakaudio.com> writes:

> I've run into a problem in attempting to define a schema for the following
> sample XML instance document:
> <Settings>
>   <setting name="Number of FooDaddies" value="3"/>
>   <setting name="FooDaddies are In the House" value="true"/>
> </Settings>
> The name values may contain white space, and thus aren't suitable as element
> names. The value of the value attributes are different in each setting
> element - i.e. I'm using anonymous type definitions to allow elements having
> the same name to have different content.

XML Schema specifically dis-allows this [1] -- the basic reasoning being
that the element<->type association should be stable within a
particular complex type.

If you really don't want to use different element names, define an
abstract type, use it <setting>, derive specialised types from it and
use xsi:type to signal which one you're using, e.g.

<element name="setting" type="my:stype"/>
<complexType name="stype">
 <attribute name="name" type="token"/>
 <attribute name="value"/>

<complexType name="s-int">
  <restriction base="my:stype">
   <attribute name="value" type="integer"/>

<complexType name="s-bool">
  <restriction base="my:stype">
   <attribute name="value" type="boolean"/>

   <setting name="Number of FooDaddies" xsi:type="s-int" value="3"/>
   <setting name="FooDaddies are In the House" xsi:type="s-bool" value="true"/>

  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 Friday, 2 February 2001 07:22:16 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:55:50 UTC